Question:medium

Consider the augmented grammar with \(\{+,* , (, ), id\}\) as the set of terminals. \[ S' \rightarrow S \] \[ S \rightarrow S + R \mid R \] \[ R \rightarrow R^{\,*} P \mid P \] \[ P \rightarrow (S) \mid id \] If \(I_0\) is the set of two LR(0) items \(\{[S' \rightarrow S.], [S \rightarrow S. + R]\}\), then \(goto(\text{closure}(I_0), +)\) contains exactly \(\underline{\hspace{1cm}}\) items.

Show Hint

The \(goto\) operation in an LR parser moves to the next state based on a specific terminal or non-terminal. The closure ensures all applicable items are included in the state.
Updated On: Jan 30, 2026
Show Solution

Correct Answer: 5

Solution and Explanation

To determine the number of items in \( goto(\text{closure}(I_0), +) \), we follow the standard construction of LR(0) item sets.

Step 1: Initial item set \( I_0 \)
The augmented grammar gives the initial LR(0) item: \[ [S' \rightarrow .S] \] Taking closure, since the dot is before nonterminal \( S \), we include all productions of \( S \) with the dot at the beginning. Hence, \[ I_0 = \{ [S' \rightarrow .S],\ [S \rightarrow .S + R],\ [S \rightarrow .R],\ [R \rightarrow .R P],\ [R \rightarrow .P] \} \] Thus, the closure of \( I_0 \) contains 5 items.

Step 2: Apply \( goto(\text{closure}(I_0), +) \)
The \( goto \) operation shifts the dot over the symbol \( + \) in all items where \( + \) immediately follows the dot. From the item: \[ [S \rightarrow .S + R] \] after shifting over \( + \), we obtain: \[ [S \rightarrow S + .R] \]

Step 3: Take closure of the resulting items
Since the dot is now before nonterminal \( R \), we include all productions of \( R \) with the dot at the beginning: \[ [R \rightarrow .R P],\ [R \rightarrow .P] \] Continuing closure where necessary, we obtain a total of 5 LR(0) items in this \( goto \) set.

Final Answer:
The number of items in \( goto(\text{closure}(I_0), +) \) is: \[ \boxed{5} \]
Was this answer helpful?
0