fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. // Regular expressions for different token types
  6. %%
  7. "int"|"float"|"char"|"if"|"else"|"for"|"while" { printf("KEYWORD: %s\n", yytext); }
  8. [a-zA-Z_][a-zA-Z0-9_]* { printf("IDENTIFIER: %s\n", yytext); }
  9. [0-9]+ { printf("INTEGER: %s\n", yytext); }
  10. [0-9]+"."[0-9]+ { printf("FLOAT: %s\n", yytext); }
  11. "=="|"<="|">="|"!="|"<"|">" { printf("RELATIONAL OPERATOR: %s\n", yytext); }
  12. "=" { printf("ASSIGNMENT OPERATOR: %s\n", yytext); }
  13. "(" { printf("LEFT PARENTHESIS: %s\n", yytext); }
  14. ")" { printf("RIGHT PARENTHESIS: %s\n", yytext); }
  15. "{" { printf("LEFT BRACE: %s\n", yytext); }
  16. "}" { printf("RIGHT BRACE: %s\n", yytext); }
  17. "+"|"-"|"*"|"/" { printf("ARITHMETIC OPERATOR: %s\n", yytext); }
  18. ";" { printf("SEMICOLON: %s\n", yytext); }
  19. [ \t\n]+ { /* Ignore whitespace */ }
  20. . { printf("UNKNOWN: %s\n", yytext); }
  21. %%
  22.  
  23. int main() {
  24. // Start lexical analysis
  25. yylex();
  26. return 0;
  27. }
  28.  
  29. int yywrap() {
  30. return 1;
  31. }
  32.  
Success #stdin #stdout #stderr 0.03s 6888KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/8C0abZ/prog:2:1: Syntax error: Operator expected
ERROR: /home/8C0abZ/prog:31:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit