fork download
  1. %{
  2. #include<stdio.h>
  3. %}
  4.  
  5. %%
  6. if|else|while|int|switch {printf("\n%s is a keyword", yytext);}
  7. [a-zA-Z_][a-zA-Z0-9_]* {printf("\n%s is an identifier", yytext);}
  8. [0-9]+ {printf("\n%s is a digit", yytext);}
  9. . {printf("\nInvalid input: %s", yytext);}
  10. %%
  11.  
  12. int main() {
  13. printf("Enter input: ");
  14. yylex(); // Start lexical analysis
  15. return 0;
  16. }
  17.  
  18. int yywrap() {
  19. return 1;
  20. }
  21.  
  22.  
Success #stdin #stdout #stderr 0.03s 6908KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/JT14V9/prog:2:3: Syntax error: Operator expected
ERROR: /home/JT14V9/prog:21:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit