fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. [0-9]+ { printf("NUMBER: %s\n", yytext); }
  7. [+] { printf("PLUS: %s\n", yytext); }
  8. [-] { printf("MINUS: %s\n", yytext); }
  9. [*] { printf("MULTIPLY: %s\n", yytext); }
  10. [/] { printf("DIVIDE: %s\n", yytext); }
  11. [ \t\n]+ { /* Ignore whitespace */ }
  12. . { printf("INVALID CHARACTER: %s\n", yytext); }
  13. %%
  14.  
  15. int main() {
  16. printf("Enter an arithmetic expression:\n");
  17. yylex();
  18. return 0;
  19. }
  20.  
  21. int yywrap() {
  22. return 1;
  23. }
  24.  
  25.  
Success #stdin #stdout #stderr 0.02s 6904KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/qQCdHw/prog:2:1: Syntax error: Operator expected
ERROR: /home/qQCdHw/prog:24:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit