fork download
  1. %{
  2. #include<stdio.h>
  3. int count=0;
  4. %}
  5. op [+-*/]
  6. letter [a-zA-Z]
  7. digitt [0-9]
  8. id {letter}*|({letter}{digitt})+
  9. notid ({digitt}{letter})+
  10. %%
  11. [\t\n]+
  12. ("int")|("float")|("char")|("case")|("default")| ("if")|("for")|("printf")|("scanf") {printf("%s is a keyword\n", yytext);}
  13. {id} {printf("%s is an identifier\n", yytext); count++;}
  14. {notid} {printf("%s is not an identifier\n", yytext);}
  15. %%
  16. int main()
  17. {
  18. FILE *fp;
  19. char file[10];
  20. printf("\nEnter the filename: ");
  21. scanf("%s", file);
  22. fp=fopen(file,"r");
  23. yyin=fp;
  24. yylex();
  25. printf("Total identifiers are: %d\n", count);
  26. return 0;
  27. }
Success #stdin #stdout #stderr 0.02s 7000KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/oQJyTb/prog:27:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit