fork download
  1. int COMMENT=0;
  2. %}
  3. identifier [a-zA-Z][a-zA-Z0-9]*
  4. %%
  5. #.* { printf("\n%s is a PREPROCESSOR DIRECTIVE",yytext);}
  6. int |float |char |double |while |for |do |if |break |continue |void |switch |case |long
  7. |struct |const |typedef |return |else |goto {printf("\n\t%s is a
  8. KEYWORD",yytext);}
  9. "/*" {COMMENT = 1;}
  10. /*{printf("\n\n\t%s is a COMMENT\n",yytext);}*/
  11. "*/" {COMMENT = 0;}
  12. /* printf("\n\n\t%s is a COMMENT\n",yytext);}*/
  13. {identifier}\( {if(!COMMENT)printf("\n\nFUNCTION\n\t%s",yytext);}
  14. { {if(!COMMENT) printf("\n BLOCK BEGINS");}
  15. } {if(!COMMENT) printf("\n BLOCK ENDS");}
  16. {identifier}(\[[0-9]*\])? {if(!COMMENT) printf("\n %s
  17. IDENTIFIER",yytext);}
  18. ".*\" {if(!COMMENT) printf("\n\t%s is a STRING",yytext);}
  19. [0-9]+ {if(!COMMENT) printf("\n\t%s is a NUMBER",yytext);}
  20. {if(!COMMENT) printf("\n\t");ECHO;printf("\n");}
  21. ( ECHO;
  22. {if(!COMMENT)printf("\n\t%s is an ASSIGNMENT OPERATOR",yytext);}
  23. <= |>= |< |== |> {if(!COMMENT) printf("\n\t%s is a RELATIONAL
  24. OPERATOR",yytext);} %%
  25. int main(int argc,char **argv) {
  26. if (argc > 1)
  27. {
  28. FILE *file;
  29. file = fopen(argv[1],"r");
  30. if(!file)
  31. {
  32. printf("could not open %s \n",argv[1]); exit(0);
  33. }
  34. yyin = file;
  35. }
  36. yylex();
  37. printf("\n\n"); return 0;
  38. } int yywrap() {
  39. return 0;
  40. }
Success #stdin #stdout #stderr 0.03s 6916KB
stdin
hello+hafdkl,kagSDH
stdout
Standard output is empty
stderr
ERROR: /home/pOLyqh/prog:40:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? Options:
+:                  spy        -:              no spy
/c|e|r|f|u|a goal:  find       .:              repeat find
a:                  abort      A:              alternatives
b:                  break      c (ret, space): creep
[depth] d:          depth      e:              exit
f:                  fail       [ndepth] g:     goals (backtrace)
h (?):              help       i:              ignore
l:                  leap       L:              listing
n:                  no debug   p:              print
r:                  retry      s:              skip
u:                  up         w:              write
m:                  exception details
C:                  toggle show context
   Exception: (3) program ? EOF: exit