Intuiting Pratt Parsing

Devs debate the simplest way to read math: fans swoon, pragmatists say “meh”

TLDR: A clear explainer shows how computers turn messy math into neat trees using a Pratt-style approach. Comments split between fans who say it finally makes sense, pragmatists pushing even simpler hand-written functions, and veterans shrugging it’s all the same—while everyone oddly agrees the original paper is “badass.”

Today’s lesson in “how computers read 2+2”: a tutorial shows how to turn flat math like a + b * c into a tidy tree so machines don’t get confused—aka an intuitive spin on Pratt parsing. The community reaction? Pure internet theater.

One camp is cheering like it’s Comic-Con. “Love Pratt parsing!” gushes one fan, celebrating a simple combo of hand-written parsing plus Pratt’s trick to respect math order. Another newcomer admits this is the first time the idea actually clicked, calling the write-up “helpful” and memorable. There’s even a history buff linking the original 1973 paper and calling it “very cool and badass” here.

Then the pragmatists roll in with a plot twist: why not skip the fancy tables and just write small, explicit functions? One commenter says that mirrors grammar guides (EBNF, a way to describe language structure) and is “even simpler.” The shrug squad fires back: stacks and recursion are automatic now, so who cares which flavor you pick—as long as you get the right tree.

Translation for non-nerds: it’s a fight over the cleanest way to teach computers the obvious—multiply before you add. The drama is real: Team Pratt vs. Team Hand‑Rolled vs. Team Why‑Bother, united only by one meme—Pratt’s paper is somehow… badass.

Key Points

  • ASTs encode operator precedence by placing operators above operands, enabling bottom‑up evaluation.
  • Monotonic precedence sequences yield simple shapes: decreasing precedence produces left‑leaning trees; increasing precedence produces right‑leaning trees.
  • Equal precedence under left associativity is treated like decreasing precedence, producing left‑leaning trees.
  • The article formalizes precedence sequences: weakly decreasing (x_i ≥ x_{i+1}) and strictly increasing (x_i < x_{i+1}).
  • When an expression shifts from increasing to decreasing precedence, the left‑leaning subtree begins at the first operator with precedence equal to or lower than the current level.

Hottest takes

“An even simpler way imo, is explicit functions instead of a precedence table,” — priceishere
“I don’t see how it matters much anymore with stacks that grow automatically, but it’s good to understand.” — hyperhello
“Its written in a very cool and badass style.” — randomNumber7
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.