fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. "int"|"float"|"if"|"else"|"while"|"for"|"return"|"char"|"double" { printf("%s : Keyword\n", yytext); }
  7.  
  8. [a-zA-Z_][a-zA-Z0-9_]* { printf("%s : Identifier\n", yytext); }
  9.  
  10. [0-9]+ { printf("%s : Constant\n", yytext); }
  11.  
  12. "+"|"-"|"*"|"/"|"="|"<"|">" { printf("%s : Operator\n", yytext); }
  13.  
  14. "//".* { printf("%s : Comment (Single-line)\n", yytext); }
  15.  
  16. [ \t\n] { /* ignore spaces */ }
  17.  
  18. . { printf("%s : Special Character\n", yytext); }
  19. %%
  20.  
  21. int main() {
  22. printf("Enter your code (press Ctrl+D to end):\n");
  23. yylex();
  24. return 0;
  25. }
  26.  
Success #stdin #stdout #stderr 0.03s 6928KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/mSvSef/prog:2:1: Syntax error: Operator expected
ERROR: /home/mSvSef/prog:25:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit