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