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. extern FILE *yyin;
  20. yyin = fopen("t1.txt","r");
  21. yylex();
  22. fclose(yyin);
  23.  
  24. return 0;
  25. }
  26.  
  27. int yywrap()
  28. {
  29. return 1;
  30. }
Success #stdin #stdout #stderr 0.02s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/3B3Rfp/prog:30:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit