Skip to content

Parse Actions โ€‹

Simple explanation โ€‹

Language tables tell the parser what to do for every combination of "current state" and "next token". There are only four moves: shift it, reduce the stack into a node, accept the finished tree, or recover.

Technical explanation โ€‹

language/tables.zig defines Action = union { none, shift: u16, reduce: ReduceRule, accept, recover }, stored per state as sorted ActionEntry lists plus GotoEntry lists for non-terminals. table.actionFor(state, symbol) and table.gotoState(state, symbol) are the only queries the engine makes, so any grammar that can be expressed as LR tables โ€” regardless of source language โ€” parses with the same loop. parser/actions.zig provides the small predicates (isShift, shiftState, reduceRule, โ€ฆ) the engine uses to dispatch.

Released under the MIT License.