← RGPV CS-501-CBGS Theory of Computation June 2020 Solved Paper
← RGPV CS-501-CBGS Theory of Computation December 2020 Solved Paper
Question
Show that the following grammar is ambiguous: S → aSbS | bSaS | ε.
Asked in: CS-501 | June 2020 | 6(b); CS-501 | December 2020 | 1(b)
Answer
A grammar is ambiguous if some word has two distinct leftmost derivations. Choose abab. First derivation: S ⇒ aSbS ⇒ abS ⇒ abaSbS ⇒ ababS ⇒ abab. Second derivation: S ⇒ aSbS ⇒ abSaSbS ⇒ abaSbS ⇒ ababS ⇒ abab. In the first, the outer a matches the second symbol b; in the second it matches the fourth symbol b. More explicitly the second derivation expands the first inner S to bSaS and then erases both inner variables and the trailing S. These distinct parse structures establish ambiguity; they do not establish inherent ambiguity of the language.
← RGPV CS-501-CBGS Theory of Computation June 2020 Solved Paper
← RGPV CS-501-CBGS Theory of Computation December 2020 Solved Paper
Discussion
Ask a question, share your thoughts or report an error.
Sign in to participate in the discussion.
Join the discussion