Handles in Right-Sentential Forms for Grammar E→E+E∣E∗E∣idE \to E + E \mid E * E \mid id

Handles in Right-Sentential Forms for Grammar E→E+E∣E∗E∣idE \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:

E→E+E∣E∗E∣idE \to E + E \mid E * E \mid id

and the input string:

id+id∗idid + 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+id∗idid + 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:

  • id∗idid * 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+id∗idid + id * id.

  2. 2
    Step 2

    content: "In the substring id∗idid * id, the production E→E∗EE \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 E→idE \to id.

  3. 3
    Step 3

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

  4. 4
    Step 4

    Again use E→idE \to id: handle is idid, replace it with EE.

  5. 5
    Step 5

    After both idid tokens participating in id∗idid * id have been reduced, the substring matching E∗EE * E is the handle. Replace E∗E⇒EE * 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+E⇒EE + 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+id∗idid + id * id

    • handle: id\boxed{id} using production E→idE \to id
    • result: E+id∗idE + id * id
  2. E+id∗idE + id * id

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

    • handle: id\boxed{id} (the right operand of ∗*) using E→idE \to id
    • result: E+E∗EE + E * E
  4. E+E∗EE + E * E

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

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

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

id, id, id, (E∗E), (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, E∗EE*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 E∗EE*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+id∗idid + id * id

id + id * id

Form 1

Handle reduced: idid → EE."

E + id * id

Form 2

Handle reduced: idid → EE."

E + E * id

Form 3

Handle reduced: idid → EE."

E + E * E

Form 4

Handle reduced: E∗EE * E → EE."

E + E

Form 5

Handle reduced: E+EE + E → EE (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: