fork download
  1. %{
  2. #include<stdio.h>
  3. int id=0,optr=0,p=0;
  4. %}
  5. %%
  6. [0-9]+ {id++; printf("identifiers are %s\n",yytext);}
  7. [+*/-] {optr++; printf("oprators are %s\n",yytext);}
  8. [(] {p++;}
  9. [)] {p--;}
  10. %%
  11. main()
  12. {
  13. printf("enter an expression \n");
  14. yylex();
  15. if(id==optr+1&&p==0&&optr>=1)
  16. {
  17. printf("this is valid expression \n");
  18. printf("count of operators = %d\n count of identifiers = %d\n ",optr,id);
  19. }
  20. else
  21. printf("this is invalid expression \n");
  22. }
  23. int yywrap()
  24. {
  25. return 1;
  26. }
Success #stdin #stdout #stderr 0.02s 6924KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/KnRl7r/prog:26:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit