fork download
  1. %{
  2. #include<stdio.h>
  3. %}
  4. %%
  5. "int"|"float"|"char" { printf("<KEYWORD,%s>\n",yytext);}
  6. [0-9]+ { printf("<NUMBER,%s>\n",yytext);}
  7. [a-zA-Z0-9_]* { printf("<IDENTIFIER,%s>\n",yytext);}
  8. "+"|"-"|"*"|"/"|"=" { printf("<OPERATOR,%s>\n",yytext);}
  9. "("|")"|"{"|"}"|";"|"#"|","|"."|"<"|">" { printf("<SYMBOL,%s>\n",yytext);}
  10. [\t\n]+
  11. %%
  12. int main(int argc,char **argv)
  13. {
  14. if (argc<2)
  15. {
  16. fprintf(stderr,"Usage:%s \n",argv[0]);
  17. exit(1); }
  18. FILE *file = fopen(argv[1],"r");
  19. if (!file)
  20. {
  21. perror("ERROR while opening the file");
  22. exit(1);
  23. }
  24. yyin=file;
  25. yylex();
  26. fclose(file);
  27. return 0;
  28. }
Success #stdin #stdout #stderr 0.02s 6968KB
stdin
a*b
stdout
Standard output is empty
stderr
ERROR: /home/UTWvwN/prog:28:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit