Content deleted Content added
Magioladitis (talk | contribs) m clean up using AWB (10274) |
Magioladitis (talk | contribs) |
||
Line 43:
The action and goto tables:
▲<td colspan="2">''action''</td>
| ''state''||'''1'''||'''$'''||'''E'''
| '''0'''||s1||||2
▲<tr align="center">
| '''3'''||r1||r1||
▲<tr align="center">
|}
▲<tr align="center">
▲<tr align="center">
▲<tr align="center">
As can be observed there is a shift-reduce conflict for state 1 and terminal '1'. This occurs because, when the action table for an LR(0) parser is created, reduce actions are inserted on a per-row basis. However, by using a follow set, reduce actions can be added with finer granularity. The follow set for this grammar:
| following||$||$||1,$
|}
A reduce only needs to be added to a particular action column if that action is in the follow set associated with that reduce. This algorithm describes whether a reduce action must be added to an action column:
function mustBeAdded(reduceAction, action){
}
Line 110 ⟶ 79:
By using mustBeAdded on each reduce action in the action table, the result is a conflict-free action table:
▲<td colspan="2">''action''</td>
| ''state''||'''1'''||'''$'''||'''E'''
| '''0'''||s1||||2
▲<tr align="center">
| '''3'''||||r1||
▲<tr align="center">
|}
▲<tr align="center">
▲<tr align="center">
▲<tr align="center">
==See also==
|