Open source · Featured · 2023

LR(0) Parser Visualization Tool.

Parsing, made visible.

RoleAuthor & maintainer
ShippedMay 2023
StackReact · JavaScript · SVG +2
abdelmaksoud.dev
presents
Admit one
lr0parser.com↗
LR(0) Parser Visualization Tool

Act I

The challenge

LR(0) parsing makes sense on a whiteboard and evaporates the moment you look away. I wanted to make it tangible: type any grammar and watch the item sets, the parse table, and the parser’s every move build in front of you.

Act II

What I built

Type a grammar and the whole LR(0) pipeline builds in the browser on a two-pane workbench: the grammar and its numbered rules stay on the left while the item sets, the canonical collection drawn as a pannable SVG automaton, the ACTION/GOTO table, and a step-through parse fill the right. A conflict keeps both actions, names the items that disagree, and says whether one symbol of lookahead would settle it; the parse grows its tree with every reduce, and a separate six-phase walkthrough builds each state one move at a time. I rebuilt the engine as a framework-free set of pure functions (grammar, item sets, table, FOLLOW, parse, tree) covered by unit tests, with the React UI just rendering their output.

Intermission, the demo

The product, playing itself

id+id$accept ✓

S → id + id · shift, shift, shift, reduce, the table decides every move

five moves of an LR(0) parse, stepping like the classroom tool does

The cast

What actually makes it work

Read the card, then flip it to watch the mechanism run.

0x01

Canonical-collection construction

A worklist closure/goto loop runs to a fixed point with structural set-equality dedup, so identical item sets collapse into one state.

how it works

Canonical-collection construction

0x02

ACTION / GOTO table that explains its conflicts

Reduce-state detection with explicit end-marker and accept handling. When two actions land in the same cell, both are kept and flagged as a shift/reduce or reduce/reduce conflict, and FOLLOW sets decide whether SLR(1) would resolve it.

how it works

ACTION / GOTO table that explains its conflicts

0x03

Table-driven parse simulation

Dual state and symbol stacks step through an input string with per-step snapshots and graceful, explained errors, and every reduce adds a node to the parse tree drawn beside the trace.

how it works

Table-driven parse simulation
Open live View on GitHub