Question
Consider the augmented grammar with as the set of terminals.
If is the set of two LR(0) items , then contains exactly __________ items.
Official answer and solution
- Official answer
- 5
- From
- Official GATE 2022 answer key
Solution
Compute the closure of the transition from on terminal symbol '+' using standard LR(0) item closure rules.
Given .
To compute :
- Since the dot is followed by end-of-string in and by the terminal '+' in , no non-terminals follow the dot. Thus .
- On symbol '+', we shift the dot over '+' in the item to obtain the kernel of the new state:
- Now compute :
- The dot is immediately before non-terminal . We add all productions for with the dot at the beginning:
- In , the dot is before non-terminal . We add all productions for with the dot at the beginning:
- In , the dot is before , which is already added.
- In and , the dots are before terminals '(' and 'id', so no further items are added.
- The dot is immediately before non-terminal . We add all productions for with the dot at the beginning:
Collecting all items in the state:
There are exactly 5 items.
Final answer
5
Common trap
Forgetting that recursively adds the productions for .
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2022 Computer Science and Information Technology (CS)
- Question
- 29 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.