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$
  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?


in Compiler Design by
retagged by | 78 views

Please log in or register to answer this question.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,375 questions
60,615 answers
95,433 users