This page builds the automaton and the ACTION/GOTO tables that LR parsing step by step uses, from the three rules below. Step forward with Next or the arrow keys.
An item E → E · + n, $ is a rule, a dot (what is read so far) and a lookahead (the token that must follow when the rule is reduced). Blue: the items being looked at. Green: the items just added.
| state | n | + | $ | GOTO E |
|---|
[A → α · B β, a] with a non-terminal B after the dot, add [B → · γ, b] for every rule B → γ and every b in FIRST(β a). Repeat until the state stops growing. FIRST(β a) walks β with the FIRST sets and the nullable set; if all of β is nullable, a is in it.goto(I, X) takes the items of I with the dot just before X, moves the dot over X (lookaheads unchanged), then takes the closure. If that set of items already is a state, reuse its number.[S′ → · E, $]. Take a state off the list, compute a goto for each symbol after a dot, put every new state on the list. Stop when the list is empty.[A → α ·, x] is a reduce in column x only. [S′ → E ·, $] is accept. Two values in one cell is a conflict.