Consider the grammar S → SbS | a. The string abababa has (A) two parse trees (B) two leftmost derivations (C) two rightmost derivations. Which is correct?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. All (A), (B) and (C) are true
Explanation
The grammar is ambiguous: abababa has several parse trees (it has four b's to split on — 5 trees in all). Each parse tree has its own leftmost and rightmost derivation, so (A), (B) and (C) all hold.
More Theory of Computation and Compilers questions
- Match List I with List II. List I: (A) Type 0, (B) Type 1, (C) Type 2, (D) Type 3. List II: (I) Finite automata, (II) Turing machine, (III)…
- Statement I: The LALR parser is more powerful than the canonical LR parser. Statement II: The SLR parser is more powerful than LALR. Which…
- Statement I: CFLs are closed under homomorphism. Statement II: CFLs are closed under complement. Which is correct?
- Assertion (A): A load-and-go assembler avoids the overhead of writing the object program out and reading it back in. Reason (R): This can b…
- Which of the following languages are not regular? A. L = {(01)ⁿ0ᵏ | n > k, k ≥ 0} B. L = {cⁿbᵏaⁿ⁺ᵏ | n ≥ 0, k ≥ 0} C. L = {0ⁿ1ᵏ | n ≠ k}
- Any string of terminals generated by the CFG S → XY, X → 0X | 1X | 0, Y → Y0 | Y1 | 0 (S is the start symbol)