fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int line_number = 1;
  6. %}
  7.  
  8. %%
  9. "int" { printf("KEYWORD: int\n"); }
  10. "return" { printf("KEYWORD: return\n"); }
  11. "printf" { printf("KEYWORD: printf\n"); }
  12. "main" { printf("IDENTIFIER: main\n"); }
  13. "Hello, World!" { printf("STRING_LITERAL: \"Hello, World!\"\n"); }
  14. "{" { printf("SYMBOL: {\n"); }
  15. "}" { printf("SYMBOL: }\n"); }
  16. "(" { printf("SYMBOL: (\n"); }
  17. ")" { printf("SYMBOL: )\n"); }
  18. ";" { printf("SYMBOL: ;\n"); }
  19. [ \t\r\n]+ { /* Ignore whitespace */ }
  20. [a-zA-Z_][a-zA-Z0-9_]* { printf("IDENTIFIER: %s\n", yytext); }
  21. [0-9]+ { printf("NUMBER: %s\n", yytext); }
  22. . { printf("UNKNOWN: %s\n", yytext); }
  23.  
  24. %%
  25.  
  26. int main() {
  27. yylex(); // Call the lexer to tokenize input
  28. return 0;
  29. }
Success #stdin #stdout #stderr 0.03s 6776KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/UD9OPx/prog:2:1: Syntax error: Operator expected
ERROR: /home/UD9OPx/prog:29:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit