Consider the following grammar G: S → XC ∣ AY X → aXb ∣ ε C → cC ∣ ε Y → bYc ∣…
Consider the following grammar G:
S → XC ∣ AY
X → aXb ∣ ε
C → cC ∣ ε
Y → bYc ∣ ε
A → aA ∣ ε
Which of the following statements is/are correct?
Answer: A. The grammar is ambiguous and the language L(G) generated by it is also ambiguous. — Final answer: The grammar is ambiguous and the language generated by it is also ambiguous (inherently ambiguous). Explanation: Grammar ambiguity: For any n ≥…
- A.
The grammar is ambiguous and the language L(G) generated by it is also ambiguous.
- B.
The grammar is ambiguous but the language L(G) generated by it is unambiguous.
- C.
The grammar is unambiguous but the language L(G) generated by it is ambiguous.
- D.
The grammar is unambiguous and the language L(G) generated by it is also unambiguous.
Attempted by 83 students.
Show answer & explanation
Correct answer: A
Final answer: The grammar is ambiguous and the language generated by it is also ambiguous (inherently ambiguous).
Explanation:
Grammar ambiguity:
For any n ≥ 0 the string a^n b^n c^n can be generated in two different ways:
Using S → X C: X ⇒ a^n b^n and C ⇒ c^n, so S ⇒ X C ⇒ a^n b^n c^n.
Using S → A Y: A ⇒ a^n and Y ⇒ b^n c^n, so S ⇒ A Y ⇒ a^n b^n c^n.
Language ambiguity:
Because the infinite family of strings {a^n b^n c^n | n ≥ 0} each has two distinct parse trees (one witnessing equality of the first two counts and the other witnessing equality of the last two counts), there are infinitely many strings with multiple parses. Therefore the language has no unambiguous grammar (it is inherently ambiguous).
A video solution is available for this question — log in and enroll to watch it.