Skip to content
Official PYQ · 2005

GATE CS 2005 Q59 — Parsing (LL, LR)

Explain with AI

Consider the grammar:

E→E+n∣E×n∣nE \rightarrow E + n \mid E \times n \mid n

For a sentence n+n×nn + n \times n, the handles in the right-sentential form of the reduction are:

Choose one option
View worked solution

Answer: D

In bottom-up parsing, a handle is a substring that matches the right-hand side of a production rule, and whose reduction to the non-terminal on the left-hand side represents one step along the reverse of a rightmost derivation.

To find the handles, let us first construct the rightmost derivation (RMD) for the input string n+n×nn + n \times n using the grammar:

E→E+n∣E×n∣nE \rightarrow E + n \mid E \times n \mid n

The rightmost derivation is as follows:

  1. E⇒E×nE \Rightarrow E \times n    (replacing the start symbol EE with E×nE \times n)
  2. ⇒E+n×n\Rightarrow E + n \times n    (replacing the rightmost non-terminal EE with E+nE + n)
  3. ⇒n+n×n\Rightarrow n + n \times n    (replacing the rightmost non-terminal EE with nn)

The bottom-up reduction process is the exact reverse of the rightmost derivation:

Step Right-Sentential Form Handle Production Used for Reduction
1 n‾+n×n\underline{n} + n \times n nn E→nE \rightarrow n
2 E+n‾×n\underline{E + n} \times n E+nE + n E→E+nE \rightarrow E + n
3 E×n‾\underline{E \times n} E×nE \times n E→E×nE \rightarrow E \times n
4 EE - -

Thus, the handles in the successive reduction steps are nn, E+nE + n, and E×nE \times n.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions