Subtopic 2 of 4
3.2Parse trees and ambiguity
A grammar is ambiguous if some string has two different parse trees (equivalently two leftmost derivations). Ambiguity can change the meaning, and ambiguous grammars are never LL(k) or LR(k).
E
E
E
num 2
+
E
num 3
*
E
num 4
- E → num: value 2
- E → num: value 3
- E → E + E: 2 + 3 = 5
- E → num: value 4
- E → E * E: 5 × 4 = 20
Grammar E → E + E | E * E | num. This tree groups the addition first: value 20.
Previous year questions: Grammars, Derivations & FIRST/FOLLOW (8)
PYQs are grouped by topic, so this is the full set for Grammars, Derivations & FIRST/FOLLOW; try the ones that match this subtopic. Open all 8 on the topic page.