Consider the following grammar: S → aSbS | bS | ϵ. Which of the following is true?
Correct Answer :
Grammar is ambiguous
Solution :
The correct option is: Grammar is ambiguous.
A grammar is defined as ambiguous if there exists at least one string in its language that has more than one leftmost derivation, more than one rightmost derivation, or more than one distinct parse tree.
Let us consider the given grammar rules:
S → aSbS | bS | ϵ
To prove that the grammar is ambiguous, we can demonstrate that a simple string generated by this grammar, such as "ab", has more than one distinct parse tree (or leftmost derivation).
Let's derive the string "ab" using two different leftmost derivations:
Leftmost Derivation 1:
S ⇒ aSbS (using S → aSbS)
S ⇒ a(ϵ)bS (replacing the first S with ϵ)
S ⇒ abS
S ⇒ ab(ϵ) (replacing S with ϵ)
S ⇒ ab
Leftmost Derivation 2:
S ⇒ aSbS (using S → aSbS)
S ⇒ aSb(ϵ) (replacing the second S with ϵ)
S ⇒ aSb
S ⇒ a(ϵ)b (replacing S with ϵ)
S ⇒ ab
Since the string "ab" can be derived using two distinct leftmost derivations, it has two distinct parse trees. Therefore, the grammar is ambiguous.
Access expert-curated educational resources and study materials—completely free.
Create, conduct, and manage professional online assessments with Mindyard. Perfect for teachers and institutes.
Copyright © 2026 Mindyard. All Rights Reserved.