Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Move line 3 to line 16.</p> <p>You also need to remove the initializers from the structure declarations - at least for C (but the C++ compiler didn't think much of it either).</p> <pre><code>struct stackoperator { char stack[10]; int top =-1; }; </code></pre> <p>To:</p> <pre><code>struct stackoperator { char stack[10]; int top; }; </code></pre> <p>In the actions, you also need to declare 'ch'.</p> <p>You also need to declare your functions - I made them static. This compiles (assuming you have a C99 compiler - the designated initializers won't work with C89 compilers):</p> <pre><code>%{ #include&lt;stdio.h&gt; struct stackoperator { char stack[10]; int top; }; struct stackoperand { int stack[10][2]; int top; }; struct stackoperator operator = { .top = -1 }; struct stackoperand operand = { .top = -1 }; int num=0; static void push(int num,int flag); static int pop(void); static int precedence(char a,char b); %} %% [0-9] {num=num*10+(*yytext-'0');push(num,1);} [-+*/] { if(precedence(operator.top,*yytext)) { char ch=pop(); push(ch,0); operand.stack[operand.top][1]=1; } push(*yytext,0); } [ \t] ; [\n] { char ch; while(operator.top!=-1) { ch=pop(); push(ch,0); } int i=0; while(i&lt;=operand.top) { if(operand.stack[operand.top][1]==1) printf(" %c ",operand.stack[operand.top][0]); else printf(" %d ",operand.stack[operand.top][0]); } } %% static void push(int num,int flag) { if(flag) { operand.top++; operand.stack[operand.top][0]=num; operand.stack[operand.top][1]=0; } else operator.stack[++operator.top]=num; } static int pop(void) { return operator.stack[operator.top--]; } static int precedence(char a,char b) { if(operator.top==-1) return 0; if((a=='*'||a=='/') &amp;&amp; (b=='+'||b=='-')) return 1; else return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload