fork download
  1. %{
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. int i=0, j=0, k=0, flag=0;
  6. char op[10], id[10];
  7. %}
  8.  
  9. %%
  10. [0-9]+ {flag++;strcpy(id[i],yytext);i++;}
  11. [+*] {flag--; strcpy(op[j],yytext);j++;}
  12. .|\n {return 0;}
  13.  
  14. %%
  15.  
  16. int main(){
  17. printf("Enter expression: ");
  18. yylex();
  19.  
  20. if(flag!=1){
  21. printf("Expression invalid");
  22. }
  23. else{
  24. for(k=0; k<j; k++){
  25.  
  26. printf(" opperator table: ");
  27. printf("%c \t",op[k]);
  28. printf(" symbol table: ");
  29. printf("%c \t",id[k]);
  30. }
  31. }
  32. }
  33.  
  34. int yywrap(){
  35. return 1;
  36. }
  37.  
  38.  
Success #stdin #stdout #stderr 0.02s 6980KB
stdin
1 + 2
stdout
Standard output is empty
stderr
ERROR: /home/3U0llO/prog:37:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit