Skip to content
Official PYQ · 2006

GATE CS 2006 Q7 — Parsing (LL, LR)

Explain with AI

Consider the following grammar

  • S→S∗ES \rightarrow S * E
  • S→ES \rightarrow E
  • E→F+EE \rightarrow F + E
  • E→FE \rightarrow F
  • F→idF \rightarrow id

Consider the following LR(0) items corresponding to the grammar above

  1. S→S∗.ES \rightarrow S *.E
  2. E→F.+EE \rightarrow F. + E
  3. E→F+.EE \rightarrow F + .E

Given the items above, which two of them will appear in the same set in the canonical sets-of-items for the grammar?

Choose one option
View worked solution

Answer: D

To determine which items appear in the same canonical set of LR(0) items, let us construct the relevant states of the LR(0) parser starting from the augmented grammar:

S′→SS' \rightarrow S
S→S∗E∣ES \rightarrow S * E \mid E
E→F+E∣FE \rightarrow F + E \mid F
F→idF \rightarrow id

Let I0I_0 be the initial state containing the item S′→.SS' \rightarrow .S. Let us trace the transitions:

  1. State I3=GOTO(I0,F)I_3 = \text{GOTO}(I_0, F): E→F.+E(Item ii)E→F.\begin{aligned} E &\rightarrow F. + E \quad \text{(Item ii)}\\ E &\rightarrow F. \end{aligned}
  2. State I1=GOTO(I0,S)I_1 = \text{GOTO}(I_0, S) contains S→S.∗ES \rightarrow S. * E. Transitioning on ∗* gives State I5=GOTO(I1,∗)I_5 = \text{GOTO}(I_1, *): S→S∗.E(Item i)E→.F+EE→.FF→.id\begin{aligned} S &\rightarrow S * . E \quad \text{(Item i)}\\ E &\rightarrow .F + E\\ E &\rightarrow .F\\ F &\rightarrow .id \end{aligned}
  3. From State I3I_3, transitioning on ++ gives State I6=GOTO(I3,+)I_6 = \text{GOTO}(I_3, +): E→F+.E(Item iii)E→.F+EE→.FF→.id\begin{aligned} E &\rightarrow F + . E \quad \text{(Item iii)}\\ E &\rightarrow .F + E\\ E &\rightarrow .F\\ F &\rightarrow .id \end{aligned}

As we can see, Item (i) is in state I5I_5, Item (ii) is in state I3I_3, and Item (iii) is in state I6I_6. No two of these items appear together in any single set of the canonical collection. Therefore, the correct option is D.

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

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