fork download
  1. %{
  2. #include "parser.tab.h"
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. %}
  7.  
  8. %%
  9.  
  10. "function" { printf("TOKEN: FUNCTION\n"); return FUNCTION; }
  11. "int" { printf("TOKEN: INT\n"); return INT; }
  12. "bool" { printf("TOKEN: BOOL\n"); return BOOL; }
  13. "true" { printf("TOKEN: TRUE\n"); return TRUE; }
  14. "false" { printf("TOKEN: FALSE\n"); return FALSE; }
  15. "if" { printf("TOKEN: IF\n"); return IF; }
  16. "else" { printf("TOKEN: ELSE\n"); return ELSE; }
  17. "while" { printf("TOKEN: WHILE\n"); return WHILE; }
  18. "do" { printf("TOKEN: DO\n"); return DO; }
  19. "for" { printf("TOKEN: FOR\n"); return FOR; }
  20. "print" { printf("TOKEN: PRINT\n"); return PRINT; }
  21. "return" { printf("TOKEN: RETURN\n"); return RETURN; }
  22.  
  23. "==" { printf("TOKEN: EQ\n"); return EQ; }
  24. "&&" { printf("TOKEN: AND\n"); return AND; }
  25. "||" { printf("TOKEN: OR\n"); return OR; }
  26. "<" { printf("TOKEN: LT\n"); return LT; }
  27. ">" { printf("TOKEN: GT\n"); return GT; }
  28. "=" { printf("TOKEN: ASSIGN\n"); return ASSIGN; }
  29. "+" { printf("TOKEN: PLUS\n"); return PLUS; }
  30. "-" { printf("TOKEN: MINUS\n"); return MINUS; }
  31. "*" { printf("TOKEN: MUL\n"); return MUL; }
  32. "/" { printf("TOKEN: DIV\n"); return DIV; }
  33. "!" { printf("TOKEN: NOT\n"); return NOT; }
  34.  
  35. "(" { printf("TOKEN: LPAREN\n"); return LPAREN; }
  36. ")" { printf("TOKEN: RPAREN\n"); return RPAREN; }
  37. "{" { printf("TOKEN: LBRACE\n"); return LBRACE; }
  38. "}" { printf("TOKEN: RBRACE\n"); return RBRACE; }
  39. ";" { printf("TOKEN: SEMICOLON\n"); return SEMICOLON; }
  40.  
  41. [0-9]+ { printf("TOKEN: NUM (%s)\n", yytext); yylval.num = atoi(yytext); return NUM; }
  42. [a-zA-Z_][a-zA-Z0-9_]* { printf("TOKEN: ID (%s)\n", yytext); yylval.id = strdup(yytext); return ID; }
  43.  
  44. [ \t\r\n]+ { /* ignorar espacios */ }
  45.  
  46. . { printf("TOKEN: ERROR (%s)\n", yytext); return ERROR; }
  47.  
  48. %%
Success #stdin #stdout #stderr 0.03s 7008KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/wpGhkK/prog:2:1: Syntax error: Operator expected
ERROR: /home/wpGhkK/prog:48:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit