fork download
  1. %{
  2. int COMMENT=0;
  3. %}
  4.  
  5. identifier [a-zA-Z_][a-zA-Z0-9_]*
  6. keyword int|float|char|double|while|for|struct|typedef|do|if|break|continue|void|switch|return|else|goto
  7.  
  8. %%
  9. #.* {printf("\n%s is a preprocessor directive",yytext);}
  10. {keyword} {printf("\n%s is a keyword",yytext);}
  11. "/*" {COMMENT=1; printf("\n\t%s is a COMMENT",yytext);}
  12. "*/" {COMMENT=0; printf("\n\t%s is a COMMENT",yytext);}
  13. {identifier}\( {if(!COMMENT) printf("\nFUNCTION \n\t%s",yytext);}
  14. \{ {if(!COMMENT) printf("\nBLOCK BEGINS");}
  15. \} {if(!COMMENT) printf("BLOCK ENDS ");}
  16. {identifier}(\[[0-9]*\])? {if(!COMMENT) printf("\n%s IDENTIFIER",yytext);}
  17. \".*\" {if(!COMMENT) printf("\n\t%s is a STRING",yytext);}
  18. [0-9]+ {if(!COMMENT) printf("\n%s is a NUMBER",yytext);}
  19. = {if(!COMMENT) printf("\n\t%s is an ASSIGNMENT OPERATOR",yytext);}
  20. \<=|\>=|==|<|> {if(!COMMENT) printf("\n\t%s is a RELATIONAL OPERATOR",yytext);}
  21. \( {ECHO;}
  22. \) {ECHO; printf("\n");}
  23. . {if(!COMMENT) ECHO;}
  24. %%
  25.  
  26. int main() {
  27. FILE *file=fopen("var.c","r");
  28. if(!file){printf("could not open file"); exit(0);}
  29. yyin=file;
  30. yylex();
  31. return 0;
  32. }
  33. int yywrap(){return 1;}
Success #stdin #stdout #stderr 0.02s 6964KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/5hrkIr/prog:2:4: Syntax error: Operator expected
ERROR: /home/5hrkIr/prog:33:22: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit