scanner.flex 450 B

12345678910111213141516171819202122232425262728
  1. %{
  2. // HEADERS
  3. #include <stdlib.h>
  4. #include "common.h"
  5. #include "parser.h"
  6. // variables maintained by the lexical analyser
  7. int yyline = 1;
  8. %}
  9. %option noyywrap
  10. %%
  11. [ \t] { }
  12. \n { yyline++; }
  13. "+" { return ADD_TOKEN; }
  14. "-" { return SUB_TOKEN; }
  15. "*" { return MULT_TOKEN; }
  16. "/" { return DIV_TOKEN; }
  17. ";" { return RESULT_TOKEN; }
  18. \-?[0-9][0-9]*(\.[0-9]*)? {
  19. yylval = atof(yytext);
  20. return NUMBER_TOKEN;
  21. }
  22. . { yyerror("unexpected character"); }
  23. %%