fork download
  1. %{
  2. int COMMENT=0;
  3. %}
  4. identifier [a-zA-Z][a-zA-Z0-9]*
  5. %%
  6. #.* {printf("\n%s is a preprocessor directive",yytext);}
  7. int |
  8. char |
  9. double |
  10. while |
  11. for |
  12. struct |
  13. typedef |
  14. do |
  15. if |
  16. break |
  17. continue |
  18. void |
  19. switch |
  20. return |
  21. else |
  22. goto {printf("\n\t%s is a keyword",yytext);}
  23. "/" {COMMENT=1;}{printf("\n\t %s is a COMMENT",yytext);}
  24. {identifier}\( {if(!COMMENT)printf("\nFUNCTION \n\t%s",yytext);}
  25. \{ {if(!COMMENT)printf("\n BLOCK BEGINS");}
  26. \} {if(!COMMENT)printf("BLOCK ENDS ");}
  27. {identifier}(\[[0-9]*\])? {if(!COMMENT) printf("\n %s IDENTIFIER",yytext);}
  28.  
  29. \".*\" {if(!COMMENT)printf("\n\t %s is a STRING",yytext);}
  30. [0-9]+ {if(!COMMENT) printf("\n %s is a NUMBER ",yytext);}
  31. \)(\:)? {if(!COMMENT)printf("\n\t");ECHO;printf("\n");}
  32. \( ECHO;
  33. = {if(!COMMENT)printf("\n\t %s is an ASSIGNMENT OPERATOR",yytext);}
  34. \<= |
  35. \>= |
  36. \< |
  37. == |
  38. \> {if(!COMMENT) printf("\n\t%s is a RELATIONAL OPERATOR",yytext);}
  39. %%
  40. int main(int argc, char **argv)
  41. {
  42. FILE *file;
  43. file=fopen("var.c","r");
  44. if(!file)
  45. {
  46. printf("could not open the file");
  47. exit(0);
  48. }
  49. yyin=file;
  50. yylex();
  51. printf("\n");
  52. return(0);
  53. }
  54. int yywrap()
  55. {
  56. return(1);
  57. }
Success #stdin #stdout #stderr 0.02s 7020KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/YM12EM/prog:58:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit