Consider the following grammar where S is the start symbol, and a and b are terminal symbols.
S →aSbS |bS |ϵ
Which of the following statements is/are true?
Correct Answer :
The grammar is ambiguous
The string abb has two distinct derivations in this grammar
The string abb has two distinct derivations in this grammar
The language generated by the grammar is undecidable
Solution :
The correct options/answers are:
1. The grammar is ambiguous
2. The string abb has two distinct derivations in this grammar
Let us analyze the given grammar and why these statements are correct.
The grammar is defined as:
S → aSbS | bS | ϵ
where S is the start variable (non-terminal), and a and b are terminal symbols, and ϵ represents the empty string.
1. Ambiguity of the Grammar:
A grammar is ambiguous if there exists at least one string in the language generated by the grammar that has more than one leftmost derivation, more than one rightmost derivation, or more than one distinct parse tree.
Let us verify this by finding derivations for the string "abb".
Derivation 1 (Leftmost Derivation):
We start with the production rule S → aSbS:
S ⇒ aSbS (using S → aSbS)
⇒ abS (using S → ϵ for the first S)
⇒ abbS (using S → bS for the remaining S)
⇒ abb (using S → ϵ for the final S)
Derivation 2 (Leftmost Derivation):
We can also derive the same string starting with S → aSbS, but applying different rules:
S ⇒ aSbS (using S → aSbS)
⇒ asbS (we keep the first S for now)
Let's substitute the first S using the rule S → bS:
S ⇒ abSbS (using S → bS for the first S)
⇒ abbS (using S → ϵ for the first S in the middle)
⇒ abb (using S → ϵ for the final S)
Since we have found two distinct derivations (and thus two distinct parse trees) for the string "abb", the string "abb" has two distinct derivations in this grammar, which directly proves that the grammar is ambiguous.
2. Decidability of Context-Free Languages:
The grammar is context-free, and context-free languages are decidable. Therefore, the statement "The language generated by the grammar is undecidable" is false. Additionally, the string "abab" has multiple derivations, making the statement about "abab" having only one rightmost derivation false as well.
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.