fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. // Define patterns for tokens
  6. %%
  7. [ \t\n]+ ; // Ignore spaces, tabs, and newlines
  8. int|float|if|else|while|return { printf("Keyword: %s\n", yytext); }
  9. [0-9]+ { printf("Number: %s\n", yytext); }
  10. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  11. "+"|"-"|"*"|"/"|"=" { printf("Operator: %s\n", yytext); }
  12. ";"|"("|")"|"{"|"}" { printf("Delimiter: %s\n", yytext); }
  13. . { printf("Unknown: %s\n", yytext); }
  14. %%
  15.  
  16. // Main function
  17. int main() {
  18. yylex(); // Start lexical analysis
  19. return 0;
  20. }
  21.  
Success #stdin #stdout #stderr 0.03s 6992KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/i669QP/prog:2:1: Syntax error: Operator expected
ERROR: /home/i669QP/prog:20:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit