fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. %option noyywrap
  7.  
  8. %%
  9. "auto" { printf("Keyword: %s\n", yytext); }
  10. "break" { printf("Keyword: %s\n", yytext); }
  11. "case" { printf("Keyword: %s\n", yytext); }
  12. "char" { printf("Keyword: %s\n", yytext); }
  13. "const" { printf("Keyword: %s\n", yytext); }
  14. "continue" { printf("Keyword: %s\n", yytext); }
  15. "return" { printf("Keyword: %s\n", yytext); }
  16. "if" { printf("Keyword: %s\n", yytext); }
  17. "else" { printf("Keyword: %s\n", yytext); }
  18. "for" { printf("Keyword: %s\n", yytext); }
  19. "while" { printf("Keyword: %s\n", yytext); }
  20. "int" { printf("Keyword: %s\n", yytext); }
  21. "float" { printf("Keyword: %s\n", yytext); }
  22. "double" { printf("Keyword: %s\n", yytext); }
  23. "void" { printf("Keyword: %s\n", yytext); }
  24. "==" { printf("Operator: %s\n", yytext); }
  25. "!=" { printf("Operator: %s\n", yytext); }
  26. "<=" { printf("Operator: %s\n", yytext); }
  27. ">=" { printf("Operator: %s\n", yytext); }
  28. "+" { printf("Operator: %s\n", yytext); }
  29. "-" { printf("Operator: %s\n", yytext); }
  30. "*" { printf("Operator: %s\n", yytext); }
  31. "/" { printf("Operator: %s\n", yytext); }
  32. "=" { printf("Operator: %s\n", yytext); }
  33. [0-9]+ { printf("Integer Constant: %s\n", yytext); }
  34. \"([^\\\"]|\\.)*\" { printf("String Constant: %s\n", yytext); }
  35. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  36. [ \t\n] { /* Ignore whitespace */ }
  37. . { printf("Unknown character: %s\n", yytext); }
  38.  
  39. %%
  40.  
  41. int main(int argc, char **argv) {
  42. yylex();
  43. return 0;
  44. }
  45.  
  46. int yyerror(char *s) {
  47. fprintf(stderr, "Error: %s\n", s);
  48. return 0;
  49. }
  50.  
Success #stdin #stdout #stderr 0.02s 6848KB
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/f9oEWR/prog:2:1: Syntax error: Operator expected
ERROR: /home/f9oEWR/prog:49: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