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