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 the empty string
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. (A) and (C) only
Explanation
In A, S → SS can split a string in several ways. In C, abbbb can be derived with the inner B or the outer B producing the second bb, giving two parse trees.
Note: no option is fully correct; the official key (A) is shown. Grammar B is also ambiguous (abab has two parse trees), so strictly all three are ambiguous; no option says so. The official key is A.
More Theory of Computation and Compilers questions
- Match List I with List II (L_R regular, L_CF context-free, L_REC recursive, L_RE recursively enumerable). List I: A. Recursively enumerable…
- Consider the regular expressions r = a(b + a)*, s = a(a + b)⁺, t = aa*b. Which relation holds between the languages they generate?
- Given below are two statements: L ∧ L = ϕ Statement I : The problem "Is 1 2 ? " is L undecidable for context sensitive languages 1 L and 2.…
- Consider the following grammars : G : S → aSb|bSa|aa 1 G : S → aSb|bSa|SS ∣ λ 2 G : S → aSb|bSa|SS ∣ a 3 G : S → aSb|bSa|SS|SSS|λ 4 Which o…
- Which grammar generates L = {aⁿbⁿ⁻³ | n > 2} over Σ = {a, b}?
- Consider the following grammar : S → 0A ∣ 0BB A → 00A ∣ λ B → 1B ∣ 11C C → B Which language does this grammar generate?