Consider the language \(L = \{a^{n}\mid n \geq 0\} \cup \{a^{n}b^{n}\mid n…
2020
Consider the language \(L = \{a^{n}\mid n \geq 0\} \cup \{a^{n}b^{n}\mid n \geq 0\}\) and the following statements.
I. \(L\) is deterministic context-free.
II. \(L\) is context-free but not deterministic context-free.
III. \(L\) is not \(LL(k)\) for any \(k\).
Which of the above statements is/are TRUE ?
Answer: C. Ⅰ and Ⅲ only — Answer: Statements "L is deterministic context-free" and "L is not LL(k) for any k" are true; "L is context-free but not deterministic context-free" is false.…
- A.
Ⅰ only
- B.
Ⅱ only
- C.
Ⅰ and Ⅲ only
- D.
Ⅲ only
Attempted by 28 students.
Show answer & explanation
Correct answer: C
Answer: Statements "L is deterministic context-free" and "L is not LL(k) for any k" are true; "L is context-free but not deterministic context-free" is false.
Why L is deterministic context-free: A deterministic PDA works as follows. In a 'push' state push each input a. If EOF is reached while still in the push state, accept (this covers a^n). On the first b move to a 'pop' state and pop one a for each b; accept at EOF only if the stack has been popped exactly to the bottom marker (this covers a^n b^n). Any mismatch (extra b or leftover a in pop state) is rejected. All transitions are deterministic.
Why L is not LL(k) for any k: For fixed k, consider the inputs a^{k+1} and a^{k+1}b^{k+1}. At the point after reading k a's the parser sees the same k-symbol lookahead in both cases, so a top-down parser with only k lookahead cannot decide whether to commit to the production that yields only a's or the production that yields a^n b^n. This ambiguity persists for every finite k, so L is not LL(k) for any k.