fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "y.tab.h"
  5. %}
  6.  
  7. /* Definitions */
  8. DIGIT [0-9]
  9. LETTER [a-zA-Z]
  10. IDENTIFIER {LETTER}({LETTER}|{DIGIT})*
  11. NUMBER {DIGIT}+
  12. STRING \"([^\"]*)\"
  13. KEYWORDS "if"|"else"|"while"|"return"|"int"|"float"|"char"|"double"
  14.  
  15. %%
  16.  
  17. {STRING} { printf("String: %s\n", yytext); }
  18. {KEYWORDS} { printf("Keyword: %s\n", yytext); }
  19. {NUMBER} { printf("Constant: %s\n", yytext); }
  20. {IDENTIFIER} { printf("Identifier: %s\n", yytext); }
  21. "\'". "\'" { printf("Literal: %s\n", yytext); }
  22.  
  23. [ \t\n]+ ; /* Ignore whitespace */
  24. . { printf("Unknown character: %s\n", yytext); }
  25.  
  26. %%
  27.  
  28. int main() {
  29. yylex();
  30. return 0;
  31. }
  32.  
  33. int yywrap() {
  34. return 1;
  35. }
  36.  
Success #stdin #stdout #stderr 0.02s 6776KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/QpNQGd/prog:2:1: Syntax error: Operator expected
ERROR: /home/QpNQGd/prog:21:11: Syntax error: Operator expected
ERROR: /home/QpNQGd/prog:35:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit