fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. %%
  7. [0-9]+ { printf("NUMBER: %s\n", yytext); }
  8. [ \t\n] ; /* Skip whitespace */
  9. "+" { printf("ADD\n"); return '+'; }
  10. "-" { printf("SUBTRACT\n"); return '-'; }
  11. "*" { printf("MULTIPLY\n"); return '*'; }
  12. "/" { printf("DIVIDE\n"); return '/'; }
  13. . { printf("Invalid character: %s\n", yytext); return 0; }
  14. %%
  15.  
  16. int main() {
  17. printf("Enter expression (e.g., 2+3, 10*5, etc.):\n");
  18. int token;
  19. while((token = yylex()) != 0) {
  20. // Loop until there are no more tokens
  21. }
  22. return 0;
  23. }
  24.  
Success #stdin #stdout #stderr 0.02s 6916KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/jAb50H/prog:2:1: Syntax error: Operator expected
ERROR: /home/jAb50H/prog:23:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit