fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. letter [a-zA-Z]
  6. digit [0-9]
  7. id {letter}({letter}|{digit})*
  8. number {digit}+(\.{digit}+)?
  9.  
  10. %%
  11.  
  12. "int"|"float"|"char"|"if"|"else"|"while"|"for"|"return"|"void"
  13. { printf("Keyword: %s\n", yytext); }
  14.  
  15. {id} { printf("Identifier: %s\n", yytext); }
  16.  
  17. {number} { printf("Number: %s\n", yytext); }
  18.  
  19. "+"|"-"|"*"|"/"|"="|"=="|"!="|"<"|">"|"<="|">="
  20. { printf("Operator: %s\n", yytext); }
  21.  
  22. ";"|","|"("|")"|"{"|"}"|"["|"]"
  23. { printf("Special Symbol: %s\n", yytext); }
  24.  
  25. [ \t\n]+ ; /* Ignore whitespace */
  26.  
  27. . { printf("Unknown Character: %s\n", yytext); }
  28.  
  29. %%
  30.  
  31. int yywrap()
  32. {
  33. return 1;
  34. }
  35.  
  36. int main()
  37. {
  38. printf("Enter the input:\n");
  39. yylex();
  40. return 0;
  41. }
Success #stdin #stdout #stderr 0.02s 6828KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/tmIp7t/prog:2:1: Syntax error: Operator expected
ERROR: /home/tmIp7t/prog:41:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit