Question
Consider the following two sets of LR(1) items of an LR(1) grammar.
Which of the following statements related to merging of the two sets in the corresponding LALR parser is/are FALSE?
- Cannot be merged since look aheads are different.
- Can be merged but will result in S-R conflict.
- Can be merged but will result in R-R conflict.
- Cannot be merged since goto on c will lead to two different sets.
Official answer and solution
- Official answer
- D
- From
- Official GATE 2013 answer key
Solution
Examine the rules for merging LR(1) item sets in LALR parser generation and check for shift-reduce and reduce-reduce conflicts.
Two LR(1) states can be merged in an LALR(1) parser if and only if they have the identical core (the set of first components of items, ignoring lookaheads).
Here, the two sets of LR(1) items are:
- Set 1:
- Set 2:
Both sets have the exact same core:
Merging the two sets yields:
Let us evaluate each statement:
- "Cannot be merged since lookaheads are different": FALSE. LALR specifically merges sets with the same core regardless of lookahead differences.
- "Can be merged but will result in S-R conflict": FALSE. A shift-reduce conflict requires at least one complete item () where the dot is at the end, and a shift item on the same terminal. Here, none of the items has the dot at the end ( has dot before non-terminal ). There are no reduce items, so no S-R conflict can occur.
- "Can be merged but will result in R-R conflict": FALSE. A reduce-reduce conflict requires two distinct complete items. With no reduce items present, no R-R conflict can occur.
- "Cannot be merged since goto on c will lead to two different sets": FALSE. The goto on from both sets will produce sets having identical cores, which are themselves merged in the LALR parser.
Since all statements 1, 2, 3, and 4 are FALSE, option (D) is correct.
D
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2013 Computer Science and Information Technology (CS)
- Question
- 40 of 65, printed as CS Q.40
- 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.