Which of the following describes a handle (as applicable to LR-parsing)…

2008

Which of the following describes a handle (as applicable to LR-parsing) appropriately?

  1. A.

    It is the position in a sentential form where the next shift or reduce operation will occur

  2. B.

    It is non-terminal whose production will be used for reduction in the next step

  3. C.

    It is a production that may be used for reduction in a future step along with a position in the sentential form where the next shift or reduce operation will occur

  4. D.

    It is the production p that will be used for reduction in the next step along with a position in the sentential form where the right hand side of the production may be found

Attempted by 107 students.

Show answer & explanation

Correct answer: D

Definition: A handle is the production that will be used for the next reduction together with the specific occurrence of that production's right-hand side in the current sentential form. In other words, it is the substring of the sentential form whose reduction is the next step in a rightmost derivation toward the start symbol.

Key points:

  • The handle identifies both the production (which production to apply) and the exact position (the occurrence of the RHS) in the sentential form.

  • It corresponds to a single reduction step in a rightmost derivation of the sentence.

  • A handle is not just a position or just a nonterminal; it is the reducible RHS occurrence together with its production.

How to recognize a handle:

  1. Look for a substring in the current sentential form that exactly matches the right-hand side of some production.

  2. Check whether replacing that substring by the production's left-hand side yields the previous sentential form in a rightmost derivation (i.e., that it is the correct reduction to move one step toward the start symbol).

  3. If both conditions hold, that substring together with the production is the handle.

Example:

  • Grammar: S -> a A c ; A -> b

  • Sentential form: a b c

  • Handle: the occurrence of 'b' that matches the right-hand side of A -> b. Reducing 'b' to A yields a A c, which is the previous step in a rightmost derivation toward the start symbol.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir