fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. "+" { printf("Operator: Addition\n"); }
  7. "-" { printf("Operator: Subtraction\n"); }
  8. "*" { printf("Operator: Multiplication\n"); }
  9. "/" { printf("Operator: Division\n"); }
  10. "%" { printf("Operator: Modulus\n"); }
  11. "=" { printf("Operator: Assignment\n"); }
  12. "==" { printf("Operator: Equality\n"); }
  13. "!=" { printf("Operator: Not Equal\n"); }
  14. "<" { printf("Operator: Less Than\n"); }
  15. "<=" { printf("Operator: Less Than or Equal\n"); }
  16. ">" { printf("Operator: Greater Than\n"); }
  17. ">=" { printf("Operator: Greater Than or Equal\n"); }
  18. "&&" { printf("Operator: Logical AND\n"); }
  19. "||" { printf("Operator: Logical OR\n"); }
  20. "!" { printf("Operator: Logical NOT\n"); }
  21. . { printf("Unknown symbol: %s\n", yytext); }
  22. \n { /* Ignore newline */ }
  23. %%
  24.  
  25. int main() {
  26. printf("Enter an operator: ");
  27. yylex();
  28. return 0;
  29. }
  30.  
  31. int yywrap() {
  32. return 1;
  33. }
  34.  
Success #stdin #stdout #stderr 0.02s 6900KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/adfBUF/prog:2:1: Syntax error: Operator expected
ERROR: /home/adfBUF/prog:33:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit