Advertisement
Guest User

Untitled

a guest
May 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. %{
  2. #include <string>
  3. #include "node.h"
  4. #include "parser.hpp"
  5. #define SAVE_TOKEN yylval.string = new std::string(yytext, yyleng)
  6. #define TOKEN(t) (yylval.token = t)
  7. extern "C" int yywrap() { }
  8. %}
  9.  
  10. %%
  11.  
  12. [ \t\n] ;
  13. "str" return TOKEN(STRINGIDENTIFIER);
  14. "num" return TOKEN(INTIDENTIFIER);
  15. "if" return TOKEN(IF);
  16. "next" return TOKEN(NEXT);
  17. "for" return TOKEN(FOR);
  18. "fnc" return TOKEN(FUNC);
  19. [a-zA-Z_][a-zA-Z0-9_]* SAVE_TOKEN; return TIDENTIFIER;
  20. [0-9]+ SAVE_TOKEN; return TINTEGER;
  21. (\".*\") SAVE_TOKEN; return TSTRING
  22. "+" return TOKEN(TPLUS);
  23. "=" return TOKEN(TEQUAL);
  24. "-" return TOKEN(TMINUS);
  25. "(" return TOKEN(LEFTPARENTHESIS);
  26. ")" return TOKEN(RIGHTPARENTHESIS);
  27. "{" return TOKEN(LEFTBRACE);
  28. "{" return TOKEN(RIGHTBRACE);
  29. "," return TOKEN(COMMA);
  30. . printf("Unknown token!n"); yyterminate();
  31.  
  32. %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement