wmluiltok.l 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. %{
  2. /*
  3. * @OSF_COPYRIGHT@
  4. * COPYRIGHT NOTICE
  5. * Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
  6. * ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
  7. * the full copyright text.
  8. */
  9. /*
  10. * HISTORY
  11. */
  12. #if defined(__STDC__)
  13. #include <string.h>
  14. #endif
  15. #ifndef XmConst
  16. #if (defined(__STDC__) && __STDC__) || !defined( NO_CONST )
  17. #define XmConst const
  18. #else
  19. #define XmConst
  20. #endif /* __STDC__ */
  21. #endif /* XmConst */
  22. /*
  23. * lex program to construct token data for WML to generate token
  24. * table data.
  25. *
  26. * stdin is the file Uil.y
  27. *
  28. * it is searched for each occurance of a line starting with '%token'
  29. * when found various fields are extracted.
  30. *
  31. * when Uil.y has been scanned the collected data is written
  32. * to stdout.
  33. */
  34. %}
  35. %a 9999 /* transitions */
  36. %{
  37. #include <stdio.h>
  38. #define TRUE 1
  39. #define FALSE 0
  40. #define MAX_SYN 10
  41. #ifdef yywrap
  42. #undef yywrap
  43. #endif
  44. typedef struct _token
  45. {
  46. char * name;
  47. char * id;
  48. char * class;
  49. int num_syn;
  50. char * syn[MAX_SYN];
  51. }
  52. TokenRec, *Token;
  53. TokenRec token[1000];
  54. TokenRec temp;
  55. void add_token ();
  56. int phase = 0;
  57. int keyword_count;
  58. int line_num = 0;
  59. int in_comment = 0;
  60. int in_include = 0;
  61. int in_token = 0;
  62. int state = 0;
  63. int used = 0;
  64. %}
  65. %%
  66. [\n] {
  67. if (in_token == TRUE)
  68. {
  69. add_token (&temp);
  70. }
  71. in_token = FALSE;
  72. line_num++;
  73. }
  74. [ \t] { /* swallow */
  75. }
  76. "/\*" { /* swallow */
  77. }
  78. ^%token {
  79. in_token = TRUE;
  80. state = 0;
  81. }
  82. [a-zA-Z0-9_]+ {
  83. if (in_token == TRUE)
  84. {
  85. switch (state)
  86. {
  87. case 0:
  88. temp.name = (char *)
  89. strcpy ((char *)
  90. malloc (strlen ((XmConst char *)yytext) + 1), (XmConst char *)yytext);
  91. temp.num_syn = 0;
  92. break;
  93. case 1:
  94. temp.id = (char *)
  95. strcpy ((char *)
  96. malloc (strlen ((XmConst char *)yytext) + 1), (XmConst char *)yytext);
  97. break;
  98. case 2:
  99. temp.class = (char *)
  100. strcpy ((char *)
  101. malloc (strlen ((XmConst char *)yytext) + 1), (XmConst char *)yytext);
  102. break;
  103. case 3:
  104. temp.syn[temp.num_syn] = (char *)
  105. strcpy ((char *)
  106. malloc (strlen ((XmConst char *)yytext) + 1), (XmConst char *)yytext);
  107. temp.num_syn++;
  108. if (temp.num_syn > MAX_SYN)
  109. printf (
  110. "ERROR, too many synonyms, line %d\n",
  111. line_num);
  112. break;
  113. }
  114. state++;
  115. }
  116. }
  117. . { /* swallow */
  118. }
  119. %%
  120. void
  121. add_token (t) /* keep sorted by name */
  122. Token t;
  123. {
  124. int i, j, k;
  125. for (j=0; j<used; j++) /* for each token */
  126. {
  127. if (strcmp (token[j].name, t->name) > 0) /* goes here */
  128. {
  129. for (i=used++; i>j; i--) /* make hole */
  130. token[i] = token[i-1];
  131. token[j] = *t; /* insert it */
  132. return;
  133. }
  134. }
  135. /*
  136. * if we get there then it goes at the end of the list
  137. */
  138. token[used++] = *t;
  139. }
  140. yywrap ()
  141. {
  142. int i, j, k;
  143. for (i=0; i<used; i++)
  144. {
  145. printf ("%s %s %s\n", token[i].name, token[i].id, token[i].class);
  146. }
  147. return (1);
  148. }