A Hugo incarnation of the blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scanner.l 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. %option noyywrap
  2. %option reentrant
  3. %option header-file="scanner.hpp"
  4. %{
  5. #include <iostream>
  6. #include "ast.hpp"
  7. #include "definition.hpp"
  8. #include "parse_driver.hpp"
  9. #include "parser.hpp"
  10. #define YY_USER_ACTION \
  11. drv.get_file_manager().write(yytext, yyleng); \
  12. LOC.step(); LOC.columns(yyleng);
  13. #define LOC drv.get_current_location()
  14. %}
  15. %%
  16. \n { drv.get_current_location().lines(); drv.get_file_manager().mark_line(); }
  17. [ ]+ {}
  18. \\ { return yy::parser::make_BACKSLASH(LOC); }
  19. \+ { return yy::parser::make_PLUS(LOC); }
  20. \* { return yy::parser::make_TIMES(LOC); }
  21. - { return yy::parser::make_MINUS(LOC); }
  22. \/ { return yy::parser::make_DIVIDE(LOC); }
  23. [0-9]+ { return yy::parser::make_INT(atoi(yytext), LOC); }
  24. defn { return yy::parser::make_DEFN(LOC); }
  25. data { return yy::parser::make_DATA(LOC); }
  26. case { return yy::parser::make_CASE(LOC); }
  27. of { return yy::parser::make_OF(LOC); }
  28. let { return yy::parser::make_LET(LOC); }
  29. in { return yy::parser::make_IN(LOC); }
  30. \{ { return yy::parser::make_OCURLY(LOC); }
  31. \} { return yy::parser::make_CCURLY(LOC); }
  32. \( { return yy::parser::make_OPAREN(LOC); }
  33. \) { return yy::parser::make_CPAREN(LOC); }
  34. , { return yy::parser::make_COMMA(LOC); }
  35. -> { return yy::parser::make_ARROW(LOC); }
  36. = { return yy::parser::make_EQUAL(LOC); }
  37. [a-z][a-zA-Z]* { return yy::parser::make_LID(std::string(yytext), LOC); }
  38. [A-Z][a-zA-Z]* { return yy::parser::make_UID(std::string(yytext), LOC); }
  39. <<EOF>> { return yy::parser::make_YYEOF(LOC); }
  40. %%