retagged by
1,134 views
0 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$
  1. As a function of $n$, what are the SLR sets of items?
  2. 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?
  3. Show the SLR parsing table that results from your decisions in part $(b)$.
  4. Repeat parts $(a)$ and $(c)$ for the unambiguous grammar, which defines the same set of expressions, shown in Fig. $4.55$. 
  5. 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?

 

Please log in or register to answer this question.

Position:
Show:

Related questions

2 2 votes
0 0 answers
834
834 views
admin asked Aug 20, 2019
834 views
In Fig. $4.56$ is a grammar for certain statements, similar to that discussed in Question $4.4.12$. Again, $e$ and $s$ are terminals standing for conditional expressions ...
0 0 votes
1 1 answer
950
950 views
admin asked Aug 20, 2019
950 views
The following grammar is proposed to remove the "danglingelse ambiguity" discussed in Section $4.3.2$:$stmt\rightarrow if\: expr\: then\: stmt\mid matchedstmt$$matchedst...
6 6 votes
1 1 answer
13.9k
13.9k views
admin asked Aug 7, 2019
13,902 views
Consider the context-free grammar:$$S\rightarrow SS + \mid SS {\ast} \mid a$$and the string $aa + a{\ast}$.Give a leftmost derivation for the string.Give a rightmost deri...
2 2 votes
0 0 answers
1.1k
1.1k views
admin asked Aug 17, 2019
1,056 views
Repeat Question $4.2.1$ for each of the following grammars and strings: $S\rightarrow 0S1\mid 01$ with string $000111$.$S\rightarrow +SS\mid \ast SS\mid a$ with string $+...