Embed presentation
Downloaded 13 times


![Problems to discuss:
74. Check whether the grammar G with production rules:
X → X+X | X*X |X|a is ambiguous or not.
Solution:
Let’s find out the derivation tree for the string "a+a*a". It
has two leftmost derivations.
Derivation 1 −
X → X+X [∵ X → X+X ]
→ a +X [∵ X → a ]
→ a+ X*X [∵ X → X*X ]
→ a+a*X [∵ X → a ]
→ a+a*a [∵ X → a ]
11/21/2017
Sampath Kumar S, AP/CSE, SECE
3](https://image.slidesharecdn.com/2-171121154541/85/2-5-ambiguity-in-context-free-grammars-3-320.jpg)
![Problems to discuss:
Derivation 2 −
X → X*X [∵ X → X*X]
→ X+X*X [∵ X → X+X ]
→ a+ X*X [∵ X → a ]
→ a+a*X [∵ X → a ]
→ a+a*a [∵ X → a ]
As there are two parse trees for a single string
"a+a*a", the grammar G is ambiguous.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
4](https://image.slidesharecdn.com/2-171121154541/85/2-5-ambiguity-in-context-free-grammars-4-320.jpg)




The document discusses ambiguity in context-free grammars. It provides examples of ambiguous grammars, including one where the grammar G with production rules X → X+X | X*X |X|a is shown to be ambiguous because the string "a+a*a" has two different leftmost derivation trees. It then lists four other grammars and briefly states that each one is ambiguous without showing the derivations.


![Problems to discuss:
74. Check whether the grammar G with production rules:
X → X+X | X*X |X|a is ambiguous or not.
Solution:
Let’s find out the derivation tree for the string "a+a*a". It
has two leftmost derivations.
Derivation 1 −
X → X+X [∵ X → X+X ]
→ a +X [∵ X → a ]
→ a+ X*X [∵ X → X*X ]
→ a+a*X [∵ X → a ]
→ a+a*a [∵ X → a ]
11/21/2017
Sampath Kumar S, AP/CSE, SECE
3](https://image.slidesharecdn.com/2-171121154541/85/2-5-ambiguity-in-context-free-grammars-3-320.jpg)
![Problems to discuss:
Derivation 2 −
X → X*X [∵ X → X*X]
→ X+X*X [∵ X → X+X ]
→ a+ X*X [∵ X → a ]
→ a+a*X [∵ X → a ]
→ a+a*a [∵ X → a ]
As there are two parse trees for a single string
"a+a*a", the grammar G is ambiguous.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
4](https://image.slidesharecdn.com/2-171121154541/85/2-5-ambiguity-in-context-free-grammars-4-320.jpg)



