fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. "int"|"float"|"char"|"if"|"else"|"while"|"for" { printf("Keyword: %s\n", yytext); }
  7. [0-9]+ { printf("Number: %s\n", yytext); }
  8. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  9. "=="|"="|"+"|"-"|"*"|"/"|"%" { printf("Operator: %s\n", yytext); }
  10. ";"|","|"(" | ")" | "{" | "}" { printf("Special Symbol: %s\n", yytext); }
  11. [ \t\n]+ { /* ignore whitespace */ }
  12. . { printf("Unknown character: %s\n", yytext); }
  13. %%
  14.  
  15. int main() {
  16. printf("Enter your source code (Press CTRL+D or CTRL+Z to end input):\n");
  17. yylex();
  18. return 0;
  19. }
  20.  
Success #stdin #stdout #stderr 0.03s 6920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/JpgciB/prog:2:1: Syntax error: Operator expected
ERROR: /home/JpgciB/prog:19:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit