THE FOLD / CHEAT / THE SHORTCUT / THE PRATT PARSING
THE PRATT PARSING
precedence from binding power
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
Pratt parsing (top-down operator-precedence) parses expressions using one idea: every operator has a binding power, and an operator binds tighter than another exactly when its power is higher. The parser reads a value, then keeps absorbing operators to its right as long as their binding power beats the current threshold, recursing to gather the right operand. That single rule reproduces the full precedence and associativity of arithmetic — × before +, parentheses, unary minus — with no grammar tables, in a handful of lines.
LIT verified live: over 8,000 random expressions, the Pratt parser’s value equals an independent recursive-descent evaluator that hard-codes the precedence levels (window.__pratt) — e.g. 2+3×4 = 14, not 20. FIG no framing; both evaluators run in-browser and are compared.
LIT verified live: over 8,000 random expressions, the Pratt parser’s value equals an independent recursive-descent evaluator that hard-codes the precedence levels (window.__pratt) — e.g. 2+3×4 = 14, not 20. FIG no framing; both evaluators run in-browser and are compared.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this at the-shortcut — binding powers are the shortcut past a stack of grammar rules; one number per operator replaces a whole precedence hierarchy. AVAN (AI) built the instrument: the Pratt loop with binding powers, and a recursive-descent evaluator with explicit precedence to check every result.
Credit as content: Vaughan Pratt (1973). The weave: David names the shortcut; I confirm Pratt’s value matches a precedence-explicit evaluator across thousands of random expressions.
Credit as content: Vaughan Pratt (1973). The weave: David names the shortcut; I confirm Pratt’s value matches a precedence-explicit evaluator across thousands of random expressions.
3 ONE DIMENSION
2 + 3 × 4: the × has higher binding power, so it gathers 3 and 4 first — the parse tree puts × below +.
4 TWO DIMENSIONS · INTERACTIVE
Generate an expression; the Pratt parser evaluates it, and a precedence-explicit reference confirms the value — precedence and parentheses honored.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: the parse tree, operators nested by binding power.
AVAN’s addition (the inverse-companion): don’t write a grammar rule per precedence level — give each operator a number. The inverse of ‘a hierarchy of grammar productions’ is ‘one binding power per operator, and the loop absorbs while power beats the threshold.’ Magenta is a low-binding operator (waits); green is the high-binding one that grabs first. Precedence from a number.
LIT Genuine Pratt parsing / top-down operator precedence (Vaughan Pratt, 1973). Verified live: over 8000 random arithmetic expressions, the Pratt parser's value equals a recursive-descent evaluator with explicit precedence levels (window.__pratt.matchesReference); e.g. 2+3×4=14.
FIG No framing: the Pratt loop (binding powers) and a precedence-explicit recursive-descent evaluator both run in-browser and are compared across thousands of expressions. The AVAN inverse is honest — replacing a hierarchy of grammar productions with one binding power per operator (absorb while power beats the threshold) is exactly Pratt's shortcut; magenta is a low-binding operator that waits, green the high-binding one that grabs first. Precedence from a number.
FIG No framing: the Pratt loop (binding powers) and a precedence-explicit recursive-descent evaluator both run in-browser and are compared across thousands of expressions. The AVAN inverse is honest — replacing a hierarchy of grammar productions with one binding power per operator (absorb while power beats the threshold) is exactly Pratt's shortcut; magenta is a low-binding operator that waits, green the high-binding one that grabs first. Precedence from a number.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE SHORTCUT · David Lee Wise (ROOT0), with AVAN