fork download
  1. %{
  2. #include<stdio.h>
  3. %}
  4.  
  5. %%
  6. // Rules for token recognition
  7. [ \t\n]+ ; // Ignore whitespace, tabs, and newlines
  8. "if"|"else"|"while"|"for" printf("Keyword: %s\n", yytext); // Recognize keywords
  9. [a-zA-Z_][a-zA-Z0-9_]* printf("Identifier: %s\n", yytext); // Recognize identifiers
  10. [0-9]+ printf("Number: %s\n", yytext); // Recognize numbers
  11. "+"|"-"|"*"|"/"|"=" printf("Operator: %s\n", yytext); // Recognize operators
  12. . printf("Unknown Symbol: %s\n", yytext); // Catch-all for unknown symbols
  13. %%
  14.  
  15. int main() {
  16. printf("Enter input to analyze:\n");
  17. yylex(); // Invoke lexical analyzer
  18. return 0;
  19. }
  20.  
Success #stdin #stdout #stderr 0.02s 6920KB
stdin
if
stdout
Standard output is empty
stderr
ERROR: /home/D1RhK7/prog:2:1: Syntax error: Operator expected
ERROR: /home/D1RhK7/prog:19:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit