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(" kwd");}
  23. "/*" {COMMENT=1;}{printf("comment");}
  24. \+ {if(!COMMENT)printf(" op-plus");}
  25. \- {if(!COMMENT)printf(" op-sub");}
  26. \* {if(!COMMENT)printf(" op-mul");}
  27. \/ {if(!COMMENT)printf(" op-div");}
  28. {identifier}\( {if(!COMMENT)printf("fun");}
  29. \{ {if(!COMMENT)printf("block begins");}
  30. \} {if(!COMMENT)printf("block ends");}
  31. {identifier}(\[[0-9]*\])? {if(!COMMENT) printf(" id");}
  32.  
  33. \".*\" {if(!COMMENT)printf("str");}
  34. [0-9]+ {if(!COMMENT) printf("num");}
  35. \)(\:)? {if(!COMMENT)printf("\n\t");ECHO;printf("\n");}
  36. \( ECHO;
  37. = {if(!COMMENT)printf(" op-equ");}
  38. \<= |
  39. \>= |
  40. \< |
  41. == |
  42. \> {if(!COMMENT) printf("rel-op");}
  43.  
  44. %%
  45.  
  46.  
  47. int main(int argc, char **argv)
  48. {
  49. FILE *file;
  50. file=fopen("input.c","r");
  51. if(!file)
  52. {
  53. printf("could not open the file");
  54. exit(0);
  55. }
  56. yyin=file;
  57. yylex();
  58. printf("\n");
  59. return(0);
  60. }
  61. int yywrap()
  62. {
  63. return(1);
  64. }
Success #stdin #stdout #stderr 0.02s 6792KB
stdin
int a+ b
stdout
Standard output is empty
stderr
ERROR: /home/0akw3c/prog:2:1: Syntax error: End of file in quoted string
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit