Skip to content

Parser Stack โ€‹

Simple explanation โ€‹

While parsing, the engine keeps a stack of "where am I in the grammar" states alongside the half-built tree pieces. Reductions pop finished pieces off and push back a single combined node.

Technical explanation โ€‹

parser/stack.zig holds two parallel ArrayLists โ€” states: []u16 and values: []u32 (subtree indices) โ€” kept in lockstep by push/pop/popMany. The stack starts with the grammar's start state; a shift pushes one entry and a reduce of N children pops N entries before pushing the goto target. Both lists live on the Parser and are cleared (capacity retained) between parses, which is why parser reuse is cheap.

Released under the MIT License.