fork download
  1. %{
  2. #include<stdio.h>
  3. int oc=0,ic=0,pc=0;
  4. %}
  5. %%
  6. [a-z|A-Z] {++ic;}
  7. [0-9]+ {++ic;}
  8. [+|\-|*|/]+ {++oc;}
  9. [(] {++pc;}
  10. [)] {--pc;}
  11. %%
  12. void main(int argc,char *argv[])
  13. {
  14. yyin = fopen(argv[1],"r");
  15. yylex();
  16. if(ic-oc==1 && pc==0)
  17. {
  18. printf("valid identifier\n");
  19. printf("operand=%d and operator=%d\n",ic,oc);
  20. }
  21. else
  22. {
  23. printf("invalid");
  24. }
  25. }
  26. int yywrap()
  27. {
  28. return -1;
  29. }
Not running #stdin #stdout 0s 0KB
stdin
5+Ab
stdout
Standard output is empty