fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. /* Definitions */
  7. DIGIT [0-9]
  8. ID [a-zA-Z_][a-zA-Z0-9_]*
  9. KEYWORDS "if"|"else"|"while"|"for"|"int"|"float"|"return"
  10.  
  11. %%
  12.  
  13. {KEYWORDS} { printf("Keyword: %s\n", yytext); }
  14. {ID} { printf("Identifier: %s\n", yytext); }
  15. {DIGIT}+ { printf("Number: %s\n", yytext); }
  16. "=="|"="|"+"|"-"|"*"|"/" { printf("Operator: %s\n", yytext); }
  17. "(" { printf("Left Parenthesis: %s\n", yytext); }
  18. ")" { printf("Right Parenthesis: %s\n", yytext); }
  19. ";" { printf("Semicolon: %s\n", yytext); }
  20. [ \t\n] { /* ignore whitespace */ }
  21. . { printf("Unknown: %s\n", yytext); }
  22.  
  23. %%
  24.  
  25. int main(int argc, char **argv) {
  26. yylex(); // Start scanning input
  27. return 0;
  28. }
  29.  
  30. int yywrap() {
  31. return 1;
  32. }
  33.  
Success #stdin #stdout #stderr 0.03s 6900KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Oeqona/prog:2:1: Syntax error: Operator expected
ERROR: /home/Oeqona/prog:32:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit