fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. "#".*
  8. { printf("Preprocessor directive: %s\n", yytext); }
  9. "int"|"float"|"char"|"void"|"return" { printf("Keyword: %s\n", yytext); }
  10. [0-9]+{ printf("Number: %s\n", yytext); }
  11. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  12. "%d" | "%f" | "%c" | "%s"{ printf("Format specifier symbol: %s\n", yytext); }
  13. "+"|"-"|"*"|"/"|"="|"<"|">"|"=="|"!="|"<="|">="{ printf("Operator: %s\n", yytext); }
  14. ";"|","|"("|")"|"{"|"}"|"["|"]" { printf("Symbol: %s\n", yytext); }
  15. [ \t\n]+ /* Skip whitespace */
  16. . { printf("Unknown character: %s\n", yytext); }
  17.  
  18. %%
  19.  
  20. int main()
  21. {
  22. yylex();
  23. return 0;
  24. }
  25.  
  26. int yywrap()
  27. {
  28. return 1;
  29. }
  30.  
Success #stdin #stdout #stderr 0.02s 6884KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/A6yaGz/prog:2:1: Syntax error: Operator expected
ERROR: /home/A6yaGz/prog:29:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit