fork download
  1. %{
  2. #include<stdio.h>
  3. int op=0,id=0,flag=0,p=0;
  4. %}
  5. %%
  6. "(" {p++;}
  7. ")" {if(p>0){
  8. p--;
  9. }
  10. else{
  11. flag=1;
  12. }}
  13. [0-9]+ {id++; printf("%s is an identifier\n",yytext);}
  14. [+*] {op++; printf("%s is an operator \n",yytext);}
  15. . {flag=1; printf("%s is a chracter \n",yytext);}
  16. %%
  17.  
  18. int main(){
  19. printf("Enter an expression");
  20. yylex();
  21.  
  22. if(id==op+1 && p==0 && flag==0){
  23. printf("Valid expreesion");
  24. printf("Number of Identifiers %d \n No of operator %d\n",id,op);
  25. }
  26. else{
  27. printf("Invalid expression");
  28. }
  29. }
Success #stdin #stdout #stderr 0.03s 6984KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/NbhdmM/prog:2:3: Syntax error: Operator expected
ERROR: /home/NbhdmM/prog:29:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit