Consider the canonical parsing of the grammar below using terminals and non-terminals with as the start symbol.
Which one of the following options gives the number of shift-reduce conflicts that will occur in the ACTION table?
View worked solution
Answer: D
To find the number of shift-reduce (S-R) conflicts in the parsing table, we construct the canonical collection of items for the augmented grammar:
An state has a shift-reduce conflict if it contains at least one shift item (e.g., ) and at least one reduce item (e.g., ). Let's trace the states containing such conflicts:
-
State :
(shift on )
(reduce )
Conflict 1 -
State :
(shift on )
(reduce )
Conflict 2 -
State :
(shift on )
(reduce )
Conflict 3 -
State :
(shift on )
(reduce )
Conflict 4 -
State where :
(reduce )
(shift on )
(shift on )
Conflict 5
No other states contain both a shift and a reduce item. Thus, there are exactly shift-reduce conflicts in the parsing table.
Free practice · Your answers on this page are not saved.
