fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. int|char|float|bool|cin|cout|main { printf("Keyword: %s\n", yytext); }
  8. [0-9]+ { printf("Number: %s\n", yytext); }
  9. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  10. [+\-*/><=]+ { printf("Operator: %s\n", yytext); }
  11. [{}();,] { printf("Symbol: %s\n", yytext); }
  12. \n { /* Ignore newlines */ }
  13. [ \t]+ { /* Ignore spaces and tabs */ }
  14.  
  15. . { printf("Invalid Token: %s\n", yytext); }
  16.  
  17. %%
  18.  
  19. int main() {
  20. printf("Enter input: ");
  21. yylex();
  22. return 0;
  23. }
  24.  
  25. int yywrap() {
  26. return 1;
  27. }
  28.  
Success #stdin #stdout #stderr 0.03s 6764KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/zQBvib/prog:2:1: Syntax error: Operator expected
ERROR: /home/zQBvib/prog:27:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit