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