fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. %%
  7. // --- Regular Expressions (token definitions) ---
  8. int [a-zA-Z_][a-zA-Z0-9_]*
  9. float [0-9]+\.[0-9]+
  10. digit [0-9]+
  11. keyword int|float|if|else|for|while|return
  12.  
  13. // --- Token Rules and Actions ---
  14. {keyword} { printf("Token: %s | Type: KEYWORD\n", yytext); }
  15. {float} { printf("Token: %s | Type: CONSTANT (FLOAT)\n", yytext); }
  16. {digit} { printf("Token: %s | Type: CONSTANT (INT)\n", yytext); }
  17. {int} { printf("Token: %s | Type: IDENTIFIER\n", yytext); }
  18. "+"|"-"|"*"|"/" { printf("Token: %s | Type: OPERATOR\n", yytext); }
  19. "(" | ")" | ";" | "," { printf("Token: %s | Type: PUNCTUATION\n", yytext); }
  20. [ \t\n\r]+ { /* Ignore whitespace */ }
  21. . { printf("Token: %s | Type: UNKNOWN\n", yytext); }
  22.  
  23. %%
  24.  
  25. // --- Main Function ---
  26. int main(int argc, char** argv) {
  27. yylex(); // Start lexical analysis
  28. return 0;
  29. }
Success #stdin #stdout #stderr 0.04s 6848KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/6ZydgE/prog:2:1: Syntax error: Operator expected
ERROR: /home/6ZydgE/prog:29:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit