home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d156 / grammars.lha / Grammars / C / scan.l < prev   
Text File  |  1988-10-02  |  6KB  |  169 lines

  1. D                       [0-9]
  2. L                       [a-zA-Z_]
  3. H                       [a-fA-F0-9]
  4. E                       [Ee][+-]?{D}+
  5. FS                      (f|F|l|L)
  6. IS                      (u|U|l|L)*
  7.  
  8. %{
  9. #include "gram.tab.h"
  10.  
  11. void count();
  12. %}
  13.  
  14. %%
  15. "/*"                    { comment(); }
  16.  
  17. "auto"                  { count(); return(AUTO); }
  18. "break"                 { count(); return(BREAK); }
  19. "case"                  { count(); return(CASE); }
  20. "char"                  { count(); return(CHAR); }
  21. "const"                 { count(); return(CONST); }
  22. "continue"              { count(); return(CONTINUE); }
  23. "default"               { count(); return(DEFAULT); }
  24. "do"                    { count(); return(DO); }
  25. "double"                { count(); return(DOUBLE); }
  26. "else"                  { count(); return(ELSE); }
  27. "enum"                  { count(); return(ENUM); }
  28. "extern"                { count(); return(EXTERN); }
  29. "float"                 { count(); return(FLOAT); }
  30. "for"                   { count(); return(FOR); }
  31. "goto"                  { count(); return(GOTO); }
  32. "if"                    { count(); return(IF); }
  33. "int"                   { count(); return(INT); }
  34. "long"                  { count(); return(LONG); }
  35. "register"              { count(); return(REGISTER); }
  36. "return"                { count(); return(RETURN); }
  37. "short"                 { count(); return(SHORT); }
  38. "signed"                { count(); return(SIGNED); }
  39. "sizeof"                { count(); return(SIZEOF); }
  40. "static"                { count(); return(STATIC); }
  41. "struct"                { count(); return(STRUCT); }
  42. "switch"                { count(); return(SWITCH); }
  43. "typedef"               { count(); return(TYPEDEF); }
  44. "union"                 { count(); return(UNION); }
  45. "unsigned"              { count(); return(UNSIGNED); }
  46. "void"                  { count(); return(VOID); }
  47. "volatile"              { count(); return(VOLATILE); }
  48. "while"                 { count(); return(WHILE); }
  49.  
  50. {L}({L}|{D})*           { count(); return(check_type()); }
  51.  
  52. 0[xX]{H}+{IS}?          { count(); return(CONSTANT); }
  53. 0[xX]{H}+{IS}?          { count(); return(CONSTANT); }
  54. 0{D}+{IS}?              { count(); return(CONSTANT); }
  55. 0{D}+{IS}?              { count(); return(CONSTANT); }
  56. {D}+{IS}?               { count(); return(CONSTANT); }
  57. {D}+{IS}?               { count(); return(CONSTANT); }
  58. '(\\.|[^\\'])+'         { count(); return(CONSTANT); }
  59.  
  60. {D}+{E}{FS}?            { count(); return(CONSTANT); }
  61. {D}*"."{D}+({E})?{FS}?  { count(); return(CONSTANT); }
  62. {D}+"."{D}*({E})?{FS}?  { count(); return(CONSTANT); }
  63.  
  64. \"(\\.|[^\\"])*\"       { count(); return(STRING_LITERAL); }
  65.  
  66. ">>="                   { count(); return(RIGHT_ASSIGN); }
  67. "<<="                   { count(); return(LEFT_ASSIGN); }
  68. "+="                    { count(); return(ADD_ASSIGN); }
  69. "-="                    { count(); return(SUB_ASSIGN); }
  70. "*="                    { count(); return(MUL_ASSIGN); }
  71. "/="                    { count(); return(DIV_ASSIGN); }
  72. "%="                    { count(); return(MOD_ASSIGN); }
  73. "&="                    { count(); return(AND_ASSIGN); }
  74. "^="                    { count(); return(XOR_ASSIGN); }
  75. "|="                    { count(); return(OR_ASSIGN); }
  76. ">>"                    { count(); return(RIGHT_OP); }
  77. "<<"                    { count(); return(LEFT_OP); }
  78. "++"                    { count(); return(INC_OP); }
  79. "--"                    { count(); return(DEC_OP); }
  80. "->"                    { count(); return(PTR_OP); }
  81. "&&"                    { count(); return(AND_OP); }
  82. "||"                    { count(); return(OR_OP); }
  83. "<="                    { count(); return(LE_OP); }
  84. ">="                    { count(); return(GE_OP); }
  85. "=="                    { count(); return(EQ_OP); }
  86. "!="                    { count(); return(NE_OP); }
  87. ";"                     { count(); return(';'); }
  88. "{"                     { count(); return('{'); }
  89. "}"                     { count(); return('}'); }
  90. ","                     { count(); return(','); }
  91. ":"                     { count(); return(':'); }
  92. "="                     { count(); return('='); }
  93. "("                     { count(); return('('); }
  94. ")"                     { count(); return(')'); }
  95. "["                     { count(); return('['); }
  96. "]"                     { count(); return(']'); }
  97. "."                     { count(); return('.'); }
  98. "&"                     { count(); return('&'); }
  99. "!"                     { count(); return('!'); }
  100. "~"                     { count(); return('~'); }
  101. "-"                     { count(); return('-'); }
  102. "+"                     { count(); return('+'); }
  103. "*"                     { count(); return('*'); }
  104. "/"                     { count(); return('/'); }
  105. "%"                     { count(); return('%'); }
  106. "<"                     { count(); return('<'); }
  107. ">"                     { count(); return('>'); }
  108. "^"                     { count(); return('^'); }
  109. "|"                     { count(); return('|'); }
  110. "?"                     { count(); return('?'); }
  111.  
  112. [ \t\v\n\f]             { count(); }
  113. .                       { /* ignore bad characters */ }
  114.  
  115. %%
  116.  
  117. comment()
  118. {
  119.         char c, c1;
  120.  
  121. loop:
  122.         while ((c = input()) != '*' && c != 0)
  123.                 putchar(c);
  124.  
  125.         if ((c1 = input()) != '/' && c != 0)
  126.         {
  127.                 unput(c1);
  128.                 goto loop;
  129.         }
  130.  
  131.         if (c != 0)
  132.                 putchar(c1);
  133. }
  134.  
  135. int column = 0;
  136.  
  137. void count()
  138. {
  139.         int i;
  140.  
  141.         for (i = 0; yytext[i] != '\0'; i++)
  142.                 if (yytext[i] == '\n')
  143.                         column = 0;
  144.                 else if (yytext[i] == '\t')
  145.                         column += 8 - (column % 8);
  146.                 else
  147.                         column++;
  148.  
  149.         ECHO;
  150. }
  151.  
  152. int check_type()
  153. {
  154. /*
  155. * pseudo code --- this is what it should check
  156. *
  157. *       if (yytext == type_name)
  158. *               return(TYPE_NAME);
  159. *
  160. *       return(IDENTIFIER);
  161. */
  162.  
  163. /*
  164. *       it actually will only return IDENTIFIER
  165. */
  166.  
  167.         return(IDENTIFIER);
  168. }
  169.