fork download
  1. %{
  2. #include<stdio.h>
  3. %}
  4.  
  5. DIGIT [0-9]
  6. ID [_a-zA-Z][a-zA-z0-9]
  7. KEYWORD [if/else/while/int]
  8. OP ">"|"<"|"="|">="|"<="|"+"|"*"|"/"|"-"
  9. SPECIALCHARACTER "'"|";"|":"|","|"("|")"
  10. %%
  11. {KEYWORD}+ {printf("%s is a keyword\n",yytext);}
  12. [0-9]+ {printf("%s is an integer\n",yytext);}
  13. {ID}+ {printf("%s is an identifier\n",yytext);}
  14. {OP}+ {printf("%s is an operator\n",yytext);}
  15. {SPECIALCHARACTER}+ {printf("%s is a special character\n",yytext);}
  16. %%
  17. int main()
  18. {
  19. printf("enter the input:");
  20. yylex();
  21. fclose(yyin);
  22.  
  23. return 0;
  24. }
  25.  
  26. int yywrap()
  27. {
  28. return 1;
  29. }
Success #stdin #stdout #stderr 0.02s 7000KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/2r2JiR/prog:29:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit