Given the following two grammars G₁ S → AB / aaB A → a / Aa B → b G₂ S → aSbS…

2014

Given the following two grammars

G₁
S → AB / aaB
A → a / Aa
B → b

G₂
S → aSbS / bSaS / λ

  1. A.

    G₁ is unambiguous and G₂ is unambiguous

  2. B.

    G₁ is unambiguous and G₂ is ambiguous

  3. C.

    G₁ is ambiguous and G₂ is unambiguous

  4. D.

    G₁ is ambiguous and G₂ is ambiguous

Attempted by 69 students.

Show answer & explanation

Correct answer: D

A grammar is ambiguous if a string has multiple leftmost derivations. For G₁, the string 'aab' derives via S→AB (A→aa, B→b) and directly via S→aaB.

For G₂, strings like 'ab' allow multiple parse trees using productions S→aSbS or S→bSaS. Thus, both grammars are ambiguous.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor