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