Facebook
From Big Owl, 2 Years ago, written in Plain Text.
This paste is a reply to Untitled from Small Crow - view diff
Embed
Download Paste or View Raw
Hits: 108
  1. %option noyywrap
  2.  
  3. %{
  4.  
  5. #include <stdlib.h>
  6. #include "global.h"
  7.  
  8.  
  9. #define YY_DECL int lexan()
  10.  
  11. int lineno = 1;
  12. int tokenval = NONE;
  13.  
  14.  
  15. %}
  16.  
  17. %%
  18.  
  19. [t ] {}
  20.  
  21. [n] {
  22.   lineno++;
  23. }
  24.  
  25. [0-9]+ {
  26.   tokenval = atoi(yytext);
  27.   return NUM;
  28. }
  29.  
  30. [A-za-z][A-za-z0-9]+ {
  31.   int p = lookup(yytext);
  32.   if (p == 0)
  33.     p = insert(yytext, ID);
  34.     tokenval = p;
  35.   return symtable[p].token;
  36. }
  37.  
  38. <<EOF>> {
  39.   yylex_destroy();
  40.   return DONE;
  41. }
  42.  
  43. . {
  44.   tokenval = NONE;
  45.   return yytext[0];
  46. }
  47.  
  48. %%