fork download
  1. %{
  2. int plus=0,minus=0,mult=0,divi=0;
  3. int opnd=0,op=0;
  4. int n;
  5. %}
  6. %%
  7. [0-9a-zA-Z]+ {opnd++;}
  8. [0-9a-zA-Z]+\+\-\*\/[0-9A-Za-z]+ {n=0;}
  9. [\+]+ {plus++;op++;}
  10. [\-]+ {minus++;op++;}
  11. [\*]+ {mult++;op++;}
  12. [\/]+ {divi++;op++;}
  13. %%
  14. main()
  15. {
  16. printf("enter the expression");
  17. yylex();
  18. printf("\n +::=%d",plus);
  19. printf("\n -::=%d",minus);
  20. printf("\n *::=%d",mult);
  21. printf("\n /::=%d",divi);
  22. printf("\n number of operators =%d",op);
  23. printf("\n number of operands =%d",opnd);
  24. if((n==0)&&(opnd=op+1))
  25. printf("\n valid expresion");
  26. else
  27. printf("\n invalid expression");
  28. }
Success #stdin #stdout #stderr 0.03s 6860KB
stdin
13+12+a+4-3/5*2
stdout
Standard output is empty
stderr
ERROR: /home/yBdYNv/prog:28:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit