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