fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. int|float|char|double { printf("Data Type: %s\n", yytext); }
  8. if|else|for|while { 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. [(),;{}] { printf("Punctuation: %s\n", yytext); }
  12. [ \t\n] ; // Ignore whitespace and newline characters
  13. . { printf("Unknown: %s\n", yytext); }
  14.  
  15. %%
  16.  
  17. int yywrap() {
  18. return 1;
  19. }
  20.  
  21. int main(int argc, char *argv[]) {
  22. ++argv, --argc;
  23. if (argc > 0)
  24. yyin = fopen(argv[0], "r");
  25. else
  26. yyin = stdin;
  27. yylex();
  28. return 0;
  29. }
  30.  
Success #stdin #stdout #stderr 0.02s 6816KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/jyhzc0/prog:2:1: Syntax error: Operator expected
ERROR: /home/jyhzc0/prog:29:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit