Consider the following grammar where 𝑆 is the start symbol, and π‘Ž and 𝑏 are…

2026

Consider the following grammar where 𝑆 is the start symbol, and π‘Ž and 𝑏 are terminal symbols.
𝑆 β†’ π‘Žπ‘†π‘π‘† ∣ 𝑏𝑆 ∣ Ο΅
Which of the following statements is/are true?

  1. A.

    (A) The grammar is ambiguous

  2. B.

    (B) The string π‘Žπ‘π‘ has two distinct derivations in this grammar

  3. C.

    (C) The string π‘Žπ‘π‘Žπ‘ has only one rightmost derivation

  4. D.

    (D) The language generated by the grammar is undecidable

Attempted by 39 students.

Show answer & explanation

Correct answer: A, B, C

SOLUTION:

OPTION A) TRUE. The grammar is ambiguous.

A grammar is ambiguous if and only if there exists at least one string in L(G) for which the grammar produces more than one parse tree.

String abb ∈ L(G) and G produces more than one parse tree for abb:

image.png

OPTION B) TRUE. The string abb has two distinct derivations in this grammar.

1st derivation:

S β‡’ aSbS
β‡’ abS
β‡’ abbS
β‡’ abb

2nd derivation:

S β‡’ aSbS
β‡’ abSbS
β‡’ abbS
β‡’ abb

Note that the question is not asking for rightmost (or leftmost) derivations. It is just asking about derivations. There are more than 2 derivations of the string abb, but the question is asking for the existence of at least two derivations.

OPTION C) TRUE. The string abab has only one rightmost derivation.

S β‡’rmd aSbS
β‡’rmd aSbaSbS
β‡’rmd aSbaSb
β‡’rmd aSbab
β‡’rmd abab

At each step, the next terminal forces a unique production choice, so no alternative rightmost derivation exists.

This fact can also be seen using the parse tree. There is only 1 parse tree that yields the string abab. Therefore, only 1 rightmost derivation exists. For any CFG, the number of rightmost derivations is the same as the number of parse trees for a given string.

OPTION D) False. The language generated by the grammar is undecidable.

This is incorrect. The given grammar is a context-free grammar (CFG), and every language generated by a CFG is a context-free language. Membership testing for context-free languages is decidable.

Therefore, the language generated by the grammar is decidable, not undecidable.

Explore the full course: Gate Guidance By Sanchit Sir