
In the above grammar,
1. how to determine the precedence of the operator?
2. If there is shift and reduce conflict, in who's favor to resolve?
3. Why are we not reducing E-->E+E, instead we are shifting. But incase of E-->id, we are reducing.
Consider the grammar
\[
\begin{array}{l}
\mathrm{E} \rightarrow \mathrm{E}+\mathrm{E} \\
\mathrm{E} \rightarrow \mathrm{E}^{*} \mathrm{E} \\
\mathrm{E} \rightarrow(\mathrm{E}) \\
\mathrm{E} \rightarrow \text { id }
\end{array}
\]
\begin{tabular}{|l|l|l|l|}
\hline \multirow{6}{*}{} & Stack & Input & Action \\
\hline & \$ & $\mathrm{id}_{1}+\mathrm{id}_{2}{ }^{\text {\% }} \mathrm{id}_{3} \mathrm{~S}$ & shift \\
\hline & Sid ${ }_{1}$ & $+\mathrm{id}_{2} * \mathrm{id}_{3} \mathrm{~S}$ & reduce by $\mathrm{E} \rightarrow$ id \\
\hline & SE & +id2*id3S & shift \\
\hline & SE + & $\mathrm{id}_{2}{ }^{*} \mathrm{id}_{3} \mathrm{~S}$ & shift \\
\hline \multirow[b]{2}{*}{Why are we not} & $\mathrm{SE}+\mathrm{id}_{2}$ & * ids ${ }^{\text {S }}$ & reduce by $\mathrm{E} \rightarrow$ id \\
\hline & SE + E & * $\mathrm{id}_{3}$ S & shift \\
\hline \multirow[t]{4}{*}{reducing $\mathrm{E} \rightarrow \mathrm{E}+\mathrm{E}$ ?} & SE + E* & $\mathrm{id}_{3} 5$ & shift \\
\hline & SE $+\mathrm{E} * \mathrm{id}_{3}$ & \$ & reduce by $\mathrm{E} \rightarrow$ id \\
\hline & SE + E * E & S & reduce by $\mathrm{E} \rightarrow \mathrm{E} * \mathrm{E}$ \\
\hline & SE + E & S & reduce by $\mathrm{E} \rightarrow \mathrm{E}+\mathrm{E}$ \\
\hline +id2* & SE & S & accept \\
\hline \multicolumn{4}{|l|}{parser} \\
\hline
\end{tabular}
and the input string id $+i d_{2}$ *
ids. Use the shiff-reduce parser
to check whether the input
Here reduction is done, which gives preference to * over +. But in
string is accepted by the the grammar, no such precedence is specified.