fork download
  1. %{
  2. #include<stdio.h>
  3. int a = 0, b = 0;
  4. void calc();
  5. %}
  6. %%
  7. [ \s\n\t]* {}
  8. [0-9]* {if(a) b = atoi(yytext);
  9. else a = atoi(yytext);}
  10. "+" {printf("%d + %d = %d\n",a,b,a+b);a=0;b=0;}
  11. "-" {printf("%d - %d = %d\n",a,b,a-b);a=0;b=0;}
  12. "*" {printf("%d * %d = %d\n",a,b,a*b);a=0;b=0;}
  13. "/" {if(b) printf("%d / %d = %d\n",a,b,a/b); else printf("INVALID\n");a=0;b=0;}
  14. "%" {if(b) printf("%d % %d = %d\n",a,b,a%b); else printf("INVALID\n");a=0;b=0;}
  15. %%
  16. int yywrap(){
  17. return 1;
  18. }
  19. int main(){
  20. yylex();
  21. fclose(yyin);
  22. }
  23.  
Success #stdin #stdout #stderr 0.03s 6904KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/ZVT2yH/prog:22:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit