fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. KEYWORD int|float|if|else|while|return
  6. IDENTIFIER [a-zA-Z_][a-zA-Z0-9_]*
  7. NUMBER [0-9]+
  8. OPERATOR \+|\-|\*|\/|=|<|>
  9. SYMBOL ;|,|\(|\)|\{|\}
  10.  
  11. %%
  12.  
  13. {KEYWORD} { printf("KEYWORD : %s\n", yytext); }
  14. {IDENTIFIER} { printf("IDENTIFIER : %s\n", yytext); }
  15. {NUMBER} { printf("NUMBER : %s\n", yytext); }
  16. {OPERATOR} { printf("OPERATOR : %s\n", yytext); }
  17. {SYMBOL} { printf("SYMBOL : %s\n", yytext); }
  18.  
  19. [ \t\n]+ ;
  20. . { printf("UNKNOWN : %s\n", yytext); }
  21.  
  22. %%
  23.  
  24. int yywrap() {
  25. return 1;
  26. }
  27.  
  28. int main() {
  29. yylex();
  30. return 0;
  31. }
  32.  
Success #stdin #stdout #stderr 0.02s 6680KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Vo9BfK/prog:2:1: Syntax error: Operator expected
ERROR: /home/Vo9BfK/prog:31:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit