fork download
  1. %{
  2. #include<stdio.h>
  3. %}
  4.  
  5. %%
  6. "+"|"-"|"*"|"/"|"="|"==" { printf("Operator: %s\n", yytext); }
  7. "("|")"|"{"|"}"|";" { printf("Symbol: %s\n", yytext); }
  8. "include"|"main"|"printf"|"return" { printf("Keyword: %s\n", yytext); }
  9. [0-9]+ { printf("Number: %s\n", yytext); }
  10. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  11. [ \t\n]+ ; /* Ignore whitespace */
  12. %%
  13.  
  14. int main(int argc, char *argv[]) {
  15. if (argc != 2) {
  16. printf("Usage: %s \n", argv[0]);
  17. return 1;
  18. }
  19.  
  20. FILE *file = fopen(argv[1], "r");
  21. if (!file) {
  22. perror("Error opening file");
  23. return 1;
  24. }
  25.  
  26. yyin = file; // Set the input stream for flex
  27. yylex();
  28. fclose(file);
  29. return 0;
  30. }
  31.  
  32. int yywrap() {
  33. return 1;
  34. }
Success #stdin #stdout #stderr 0.02s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/TKnlVO/prog:34:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit