fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. "int"|"float"|"char" { printf("Keyword: %s\n", yytext); }
  8. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  9. [0-9]+ { printf("Constant: %s\n", yytext); }
  10. "=" { printf("%s is an Assignment Operator\n", yytext); }
  11. "+"|"-"|"*" { printf("%s is an Operator\n", yytext); }
  12. [ \t\n]+ { /* Ignore whitespace */ }
  13. . { printf("Invalid token: %s\n", yytext); }
  14.  
  15. %%
  16.  
  17. int main() {
  18. printf("Enter code: ");
  19. yylex(); // Start scanning
  20. return 0;
  21. }
  22.  
Success #stdin #stdout #stderr 0.02s 6952KB
stdin
int main() {
    int a = 5;
    float b = 3.14;
    if (a > b) {
        printf("Hello, World!");
    }
    return 0;
}
stdout
Standard output is empty
stderr
ERROR: /home/Mlzwf6/prog:2:1: Syntax error: Operator expected
ERROR: /home/Mlzwf6/prog:21:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ?    Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ?    Call: (3) program ? EOF: exit