• edited by
6,091 views
26 26 votes
  1. Remove left-recursion from the following grammar: $S \rightarrow Sa \mid Sb \mid a \mid b$
  2. Consider the following grammar: 

             $S \rightarrow aSbS\mid bSaS \mid \epsilon$

             Construct all possible parse trees for the string abab. Is the grammar ambiguous?

3 Answers

Best answer
44 44 votes
  1. $S \rightarrow aS'\mid bS'$
    $S' \rightarrow aS' \mid bS' \mid \epsilon$
     
  2. $S \rightarrow aSbS \rightarrow abS \rightarrow abaSbS \rightarrow ababS \rightarrow abab$
    $S \rightarrow aSbS \rightarrow abSaSbS \rightarrow abaSbS \rightarrow ababS \rightarrow abab$ 

The above two derivations corresponds to two different parse trees and hence the grammar is ambiguous.

• edited by
6 6 votes

Remove left-recursion from the following grammar:

a) 

so by the basic rule==>

b)

left side parsing: S->aSbS->abS->abaSbS>ababS->abab

right side parsing:S->aSbS->abSaSbS->abaSbS->ababS->abab so it is ambiguous
 

Position:
Show:

Related questions

49 49 votes
6 answers 6 answers
27.5k
27.5k views
Kathleen asked Sep 14, 2014
27,525 views
Which of the following statements is false?An unambiguous grammar has same leftmost and rightmost derivationAn LL(1) parser is a top-down parserLALR is more powerful than...
14 14 votes
2 answers 2 answers
3.5k
3.5k views
Kathleen asked Sep 14, 2014
3,456 views
The syntax of the repeat-until statement is given by the following grammar$S \rightarrow\text{ repeat }S_1\text{ until }E$where E stands for expressions, $S$ and $S_1$ st...
32 32 votes
2 answers 2 answers
7.6k
7.6k views
Kathleen asked Sep 14, 2014
7,585 views
Consider the following grammar with terminal alphabet $\Sigma =\{a,(,),+,* \}$ and start symbol $E$. The production rules of the grammar are:$ E \rightarrow aA$$ E \right...
45 45 votes
2 answers 2 answers
15.8k
15.8k views
Kathleen asked Sep 14, 2014
15,782 views
The process of assigning load addresses to the various parts of the program and adjusting the code and the data in the program to reflect the assigned addresses is called...