fork download
  1. %{
  2. #include<stdio.h>
  3. #include<string.h>
  4. int count=0;
  5. %}
  6. op [+ * / %]
  7. asop [=]
  8. reop [<= < >= > != ==]
  9. letter [a-zA-Z]
  10. digit [0-9]
  11. id {letter}*|({letter}{digit})+
  12. notid ({digit}{letter})+
  13. floati {digit}+(\.{digit}+)
  14. inti {digit}+
  15. logop [|| && !]
  16. indeop [++ --]
  17. spop [, ;]
  18. %%
  19. [ \t\n]+
  20. \#.+ {printf("HeaderFile: %s\n", yytext);}
  21. auto|double|int|struct|break|else|long|switch|case|enum|register|typedef|char|extern|return|union|const|float|short|unsigned|continue|for|signed|void|default|goto|sizeof|volatile|do|if|static|while {printf ("%s is a keyword\n",yytext); count++; }
  22. {id} {printf("%s is an identifier\n",yytext);count++; }
  23. {notid} {printf("%s is not an identifier\n",yytext); }
  24. {floati} {printf("%s is a floating point\n",yytext);count++; }
  25. {inti} {printf("%s is a integer num\n",yytext);count++; }
  26. {asop} {printf("%s is a assign op\n",yytext);count++; }
  27. {reop} {printf("%s is an relation op\n",yytext);count++; }
  28. {logop} {printf("%s is an logical op\n",yytext);count++; }
  29. "-"|{op} {printf("%s is an operator\n",yytext);count++; }
  30. "("|")" | {spop} {printf("%s is a special operator\n",yytext); count++; }
  31. {indeop} {printf("%s is a increment\n",yytext);count++; }
  32. \".*\" {printf("%s is a string\n",yytext);count++; }
  33. %%
  34. int main()
  35. {
  36. FILE *fp;
  37. char file[30];
  38. printf("\nEnter the filename: ");
  39. scanf("%s", file);
  40. fp=fopen(file,"r");
  41. yyin=fp;
  42. yylex();
  43. printf("Total identifiers are: %d\n",count);
  44. return 0;
  45. }
  46. int yywrap()
  47. {
  48. return 1;
  49. }
  50.  
Success #stdin #stdout #stderr 0.02s 7084KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/BPgE77/prog:49:1: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit