fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. // Definitions section
  6. %%
  7. [ \t\n]+ ; // Ignore whitespace
  8. int { printf("Keyword: int\n"); }
  9. return { printf("Keyword: return\n"); }
  10. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  11. [0-9]+ { printf("Number: %s\n", yytext); }
  12. . { printf("Unknown character: %s\n", yytext); }
  13. %%
  14.  
  15. // User code section
  16. int main() {
  17. yylex(); // Call the lexer
  18. return 0;
  19. }
  20.  
  21. int yywrap() {
  22. return 1; // Indicate end of input
  23. }
  24.  
Success #stdin #stdout #stderr 0.03s 6924KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/KHGzMM/prog:2:1: Syntax error: Operator expected
ERROR: /home/KHGzMM/prog:23:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit