The Gateway to Computer Science Excellence

0 votes

The following is an ambiguous grammar for expressions with $n$ binary, infix operators, at $n$ different levels of precedence:

- $E\rightarrow E\theta_{1}E\mid E\theta_{2}E\mid \cdot\cdot\cdot E\theta_{n}E\mid(E)\mid id$

- As a function of $n$, what are the SLR sets of items?
- How would you resolve the conflicts in the SLR items so that all operators are left associative, and $\theta_{1}$ takes precedence over $\theta_{2}$, which takes precedence over $\theta_{3}$, and so on?
- Show the SLR parsing table that results from your decisions in part $(b)$.
- Repeat parts $(a)$ and $(c)$ for the unambiguous grammar, which defines the same set of expressions, shown in Fig. $4.55$.
- How do the counts of the number of sets of items and the sizes of the tables for the two (ambiguous and unambiguous) grammars compare? What does that comparison tell you about the use of ambiguous expression grammars?

52,375 questions

60,615 answers

202,052 comments

95,433 users