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. [0-9]+ { printf("Integer: %s\n", yytext); }
  12. [0-9]+\.[0-9]+ { printf("Float: %s\n", yytext); }
  13. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  14. "=" { printf("Operator: =\n"); }
  15. "==" { printf("Operator: ==\n"); }
  16. "+" { printf("Operator: +\n"); }
  17. "-" { printf("Operator: -\n"); }
  18. "*" { printf("Operator: *\n"); }
  19. "/" { printf("Operator: /\n"); }
  20. ";" { printf("Semicolon: ;\n"); }
  21. [ \t\n\r] { /* Ignore whitespace */ }
  22. . { printf("Unknown character: %s\n", yytext); }
  23. %%
  24.  
  25. int main() {
  26. yylex(); // Start the lexical analysis
  27. return 0;
  28. }
  29.  
  30.  
Success #stdin #stdout #stderr 0.03s 6916KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/F84kMJ/prog:2:1: Syntax error: Operator expected
ERROR: /home/F84kMJ/prog:29:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit