fork download
  1. %{
  2. #undef yywrap
  3. #define yywrap() 1
  4. #include<stdio.h>
  5. int statements = 0;
  6. int ids = 0;
  7. int assign = 0;
  8. int rel = 0;
  9. int keywords = 0;
  10. int integers = 0;
  11. %}
  12. DIGIT [0-9]
  13. LETTER [A-Za-z]
  14. TYPE int|char|bool|float|void|for|do|while|if|else|return|void|printf|scanf|main|include|stdio
  15. PARAN "{"|"}"|"("|")"
  16. RELOP "+"|"-"|"*"|"%"|"&"|"/"|"<"|">"
  17. EXPR ","|";"|"\""|"."
  18. %option yylineno
  19. %option noyywrap
  20. %%
  21. {TYPE} {fprintf(yyout, " Keyword : %s\n", yytext);}
  22. {RELOP} {fprintf(yyout, " Relational Operator : %s\n" , yytext);}
  23. {PARAN} {fprintf(yyout, "Paranthesis : %s\n", yytext);}
  24. {EXPR} {fprintf(yyout, " Supporters : %s\n", yytext);}
  25. [0-9]+|[a-zA-Z][a-zA-Z0-9_]* {fprintf(yyout, "Identifier : %s\n" ,yytext);}
  26. %%
  27. void main(int argc, char **argv)
  28. {
  29. extern FILE *yyin, *yyout;
  30. yyin = fopen("1.c", "r");
  31. yyout = fopen("Output2.txt", "w");
  32. yylex();
  33. printf("Successs! ! !\n");
  34. }
Success #stdin #stdout #stderr 0.02s 6868KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/IXltB5/prog:34:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit