Scan.l 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. %{
  2. #define YYSTYPE double
  3. #include "cal_tab.h"
  4. int c;
  5. extern YYSTYPE yylval;
  6. double translate(int type);
  7. void count(void);
  8. void setLastVar(void);
  9. int lookup(int *typeOfObject);
  10. struct lextab *lexswitch(struct lextab *lp);
  11. #define INTCONST 1
  12. #define DBLCONST 2
  13. #define HEXCONST 3
  14. #define VARIABLE 4
  15. #define OTHER 5
  16. %}
  17. digit = [0-9];
  18. letter = [a-zA-Z_];
  19. hex = [a-fA-F0-9];
  20. /* -- */
  21. space = [\40];
  22. /*number = (digit* | "-" digit*);*/
  23. number = digit*;
  24. exp = [Ee] number;
  25. doubl = number "." (digit* | digit* exp);
  26. %%
  27. hex hex* [hH] { count(); yylval = translate(HEXCONST); return VALUE; }
  28. digit* { count(); yylval = translate(INTCONST); return VALUE; }
  29. digit digit* [Dd] { count(); yylval = translate(INTCONST); return VALUE; }
  30. doubl { count(); yylval = translate(DBLCONST); return VALUE; }
  31. letter* { count(); { int typeOfObject; setLastVar(); yylval = lookup(&typeOfObject); return typeOfObject; }}
  32. letter (letter|digit)* { count(); { int typeOfObject; setLastVar(); yylval = lookup(&typeOfObject); return typeOfObject; }}
  33. '+' { count(); return '+'; }
  34. '-' { count(); return '-'; }
  35. '*' { count(); return '*'; }
  36. '/' { count(); return '/'; }
  37. '%' { count(); return '%'; }
  38. '&' { count(); return '&'; }
  39. '|' { count(); return '|'; }
  40. '(' { count(); return '('; }
  41. ')' { count(); return ')'; }
  42. '=' { count(); return '='; }
  43. ',' { count(); return ','; }
  44. ';' { count(); return ';'; }
  45. [ \t\v\f] { count(); }
  46. . { count(); }
  47. %%