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