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