Which of the following grammars is (are) ambiguous? (A) s → ss | asb | bsa | (B) s → asbs | bsas | λ (C) s → aAB A → bBb B → A | λ where λ denotes empty string Choose the correct answer from the options given below:
Which of the following grammars is (are) ambiguous? (A) s → ss | asb | bsa | (B) s → asbs | bsas | λ (C) s → aAB A → bBb B → A | λ where λ denotes empty string Choose the correct answer from the options given below: Correct Answer (A) (B) and (C)
The correct answer is option 4.
Key Points
A is ambiguous because λ can be generated using leftmost derivation having two different parse trees with an empty string.
[ alt="F1 Shraddha Raju 03.04.2021 D26" src="//storage.googleapis.com/tb-img/production/21/04/F1_Shraddha_Raju_03.04.2021_D26.png" style="width: 118px; height: 125px;">
B is ambiguous grammar with string abab.
[ alt="F1 Shraddha Raju 03.04.2021 D27" src="//storage.googleapis.com/tb-img/production/21/04/F1_Shraddha_Raju_03.04.2021_D27.png" style="width: 339px; height: 201px;">
C is an ambiguous grammar with string abbbb.
[ alt="F1 Shraddha Raju 03.04.2021 D28" src="//storage.googleapis.com/tb-img/production/21/04/F1_Shraddha_Raju_03.04.2021_D28.png" style="width: 265px; height: 227px;">
∴ Hence the correct answer is (A) (B) and (C).