Handles in Right-Sentential Forms for Grammar EE+EEEidE \to E + E \mid E * E \mid id

Handles in Right-Sentential Forms for Grammar EE+EEEidE \to E + E \mid E * E \mid id

Verified Sources
Sep 12, 2026

In bottom-up (shift-reduce) parsing, the parser repeatedly reduces a substring that is a handle of the current right-sentential form . Intuitively, a handle is exactly the piece of the current sentential form that was produced most recently by a rightmost derivation; reducing it simulates reversing that last derivation step. This “rightmost derivation in reverse” viewpoint is standard in LR parsing theory. In LR parsing, the notion is formalized by splitting a right-sentential form into αβγ\alpha \beta \gamma, where β\beta is the handle and α\alpha is the viable prefix context.

For the grammar:

EE+EEEidE \to E + E \mid E * E \mid id

and the input string:

id+ididid + id * id

we will find the handles of the right sentential forms that appear during the reduction sequence for that specific string. The key idea is: each reduction replaces the RHS β\beta by its LHS AA in one step, so the handle is the β\beta that matches some production AβA \to \beta.

Footnotes

  1. LR parser - Wikipedia - Discusses right-sentential forms, viable prefixes, and defines the handle β within LR parsing theory. 2

Handles and Viable Prefixes | Easiest Explanation | Compiler Design (GATE 2005) | Parser | Part-1

Keyword anchors

  • handle
  • right-sentential form
  • rightmost derivation
  • viable prefix

These terms are tightly connected: LR parsing uses viable prefixes built from right-sentential forms, and a reduction occurs when the handle (RHS of a production) can be reduced to the corresponding nonterminal.

Footnotes

  1. LR parser - Wikipedia - Discusses right-sentential forms, viable prefixes, and defines the handle β within LR parsing theory.

Compute the reduction sequence for id+ididid + id * id

A right-sentential form γ\gamma is reduced by choosing a substring β\beta such that β\beta is the RHS of some production AβA \to \beta, and replacing β\beta with AA in γ\gamma. The handle is precisely that β\beta.

We will use the natural operator structure implied by the grammar reductions for the specific input:

  • ididid * id forms one EE
  • then id+Eid + E forms another EE

We list the right sentential forms during the bottom-up reduction, from terminals toward the start symbol EE. (This is the reverse of a rightmost derivation.) The handles are marked at each step.

Footnotes

  1. LR parser - Wikipedia - Discusses right-sentential forms, viable prefixes, and defines the handle β within LR parsing theory.

Finding handles by reverse rightmost reductions

  1. 1
    Step 1

    Current right-sentential form is id+ididid + id * id.

  2. 2
    Step 2

    content: "In the substring ididid * id, the production EEEE \to E * E matches after previously reducing idid’s to EE (which are done in the next steps if needed). For handle identification on the current right-sentential form, the next reducible RHS instance is the idid that must become EE; thus we start by reducing each idid as a handle of the form EidE \to id.

  3. 3
    Step 3

    content: "Right-sentential form at this moment contains an idid which matches EidE \to id, so the handle is idid and the replacement is idEid \Rightarrow E.

  4. 4
    Step 4

    Again use EidE \to id: handle is idid, replace it with EE.

  5. 5
    Step 5

    After both idid tokens participating in ididid * id have been reduced, the substring matching EEE * E is the handle. Replace EEEE * E \Rightarrow E.

  6. 6
    Step 6

    Finally, with the entire expression shaped as E+EE + E, the substring E+EE + E is the handle. Replace E+EEE + E \Rightarrow E.

The handles (explicitly stated)

A clean way to present handles is to write a concrete bottom-up reduction chain (each step reduces one handle β\beta to its AA):

Consider the following reduction sequence (each “\Rightarrow” is one reduction step):

  1. id+ididid + id * id

    • handle: id\boxed{id} using production EidE \to id
    • result: E+ididE + id * id
  2. E+ididE + id * id

    • handle: id\boxed{id} (the left operand of *) using EidE \to id
    • result: E+EidE + E * id
  3. E+EidE + E * id

    • handle: id\boxed{id} (the right operand of *) using EidE \to id
    • result: E+EEE + E * E
  4. E+EEE + E * E

    • handle: EE\boxed{E * E} using EEEE \to E * E
    • result: E+EE + E
  5. E+EE + E

    • handle: E+E\boxed{E + E} using EE+EE \to E + E
    • result: EE

Thus, the handles of the right sentential forms during the reduction are, in order:

id, id, id, (EE), (E+E).\boxed{id,\ id,\ id,\ (E * E),\ (E + E)}.

This matches the LR “reduce the handle” idea: at each step, the handle is the RHS of a production that can be reduced in reverse of a rightmost derivation.

Footnotes

  1. LR parser - Wikipedia - Discusses right-sentential forms, viable prefixes, and defines the handle β within LR parsing theory.

type="tip" title="Pro Tip: How to spot a handle quickly" content="On a current right-sentential form, scan for a substring that is exactly the RHS of one production (here: idid, EEE*E, or E+EE+E). That RHS instance (at the correct position) is the handle reduced in one step in the bottom-up process. Handles are defined relative to right-sentential forms, not arbitrary substrings. "

Footnotes

  1. LR parser - Wikipedia - Discusses right-sentential forms, viable prefixes, and defines the handle β within LR parsing theory.

type="warning" title="Warning: Handles are not “any reducible-looking RHS”" content="Even if a substring resembles EEE*E or E+EE+E, it must correspond to a single reverse step of a rightmost derivation in that specific right-sentential form. LR parsing formalizes this via viable prefixes and the handle definition within right-sentential forms. "

Footnotes

  1. LR parser - Wikipedia - Discusses right-sentential forms, viable prefixes, and defines the handle β within LR parsing theory.

Reduction roadmap for id+ididid + id * id

id + id * id

Form 1

Handle reduced: ididEE."

E + id * id

Form 2

Handle reduced: ididEE."

E + E * id

Form 3

Handle reduced: ididEE."

E + E * E

Form 4

Handle reduced: EEE * EEE."

E + E

Form 5

Handle reduced: E+EE + EEE (accept)."

Handles encountered in reduction order

Each bar corresponds to one reduction step's handle β

Quick conceptual checks

Handles & right-sentential forms (self-test)

1 / 4
Question · Term

Handle of a right-sentential form

Click to reveal
Answer · Definition

A substring β such that β is the RHS of a production A → β, occurring at the handle position in the right-sentential form; reducing β → A reverses the last rightmost derivation step.

Footnotes

  1. LR parser - Wikipedia - Discusses right-sentential forms, viable prefixes, and defines the handle β within LR parsing theory.

Knowledge Check

Question 1 of 3
Q1Single choice

In LR parsing, the handle of a right-sentential form is (roughly) the substring that corresponds to: