Which of the following derivations does a top-down parser use while parsing an…

2000

Which of the following derivations does a top-down parser use while parsing an input string? The input is assumed to be scanned in left to right order.

  1. A.

    Leftmost derivation

  2. B.

    Leftmost derivation traced out in reverse

  3. C.

    Rightmost derivation

  4. D.

    Rightmost derivation traced out in reverse

Attempted by 45 students.

Show answer & explanation

Correct answer: A

A top-down parser constructs a parse tree starting from the root (the start symbol) and works its way down to the leaves. At each step, it selects a non-terminal and replaces it with one of its production rules. Crucially, to match the input string scanned from left to right, the parser must always expand the leftmost non-terminal in the current sentential form. This process generates a sequence of strings where each step replaces the leftmost non-terminal, which is precisely the definition of a leftmost derivation. Therefore, option A is correct.

Option B describes reverse top-down parsing or bottom-up techniques incorrectly. Option C and D refer to rightmost derivations, which are characteristic of bottom-up parsers (like LR parsers) that reduce the input string from left to right, effectively building a rightmost derivation in reverse. Since top-down parsing proceeds by predicting and expanding the leftmost symbols first, it strictly follows a leftmost derivation path.

Explore the full course: Gate Guidance By Sanchit Sir