All mock tests are FREE till 31 December — register to save your progress
Unit 8 · Theory of Computation and Compilers Paper 2 CS · September 2022

Consider the grammar S → SbS | a and the string abababa. Consider the statements: the string has
(A) two parse trees
(B) two leftmost derivations
(C) two rightmost derivations
Which of the following is correct?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. All of (A), (B) and (C) are true

Explanation

The grammar is ambiguous: abababa has more than one parse tree (in fact Catalan(3) = 5). Each parse tree corresponds to one leftmost and one rightmost derivation, so all three statements hold.

More Theory of Computation and Compilers questions