# You Don't Need to Understand Pratt Parsing to Use It

Original title: Pratt parsing is a black box

> Hacker News story 50357457 · language: en · submitted 2026-11-03
> Web version: https://zeli.app/story/50357457
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 61 · by [ibobev](<https://news.ycombinator.com/user?id=ibobev>) · 💬 35
[original](<https://vinipsmaker.github.io/blog/article/pratt-parsing-is-a-black-box/>) · [HN discussion](<https://news.ycombinator.com/item?id=50357457>)

## Summary

Pratt parsing fits in nine lines of code, and that snippet is the least important thing to learn. What matters is the mindset: register semantic actions on terminals rather than production rules, splitting tokens into nuds (expect nothing to the left) and leds (expect something). The author, who built a Pratt-based compiler without studying the algorithm, argues this shift eliminates left-recursion headaches, backtracking, and repeated actions, and turns table gaps into extension points for macros and custom operators.

## Key quote

> Pratt takes parsing, which is a really complicated thing, and reduces it to one simple question: what do we expect to see to the left of a token?

## HN discussion (35 comments)

### [vinipsmaker](<https://news.ycombinator.com/item?id=50358134>)

> Author here.
>
> I was using Pratt parsing for almost a year in a macro-heavy language that I've been developing before finally sitting down on my chair to write my thoughts on Pratt parsing. Code is closed right now because I don't want LLMs training on my code before 0.1, but I'll open source it again later.
>
> Happy to answer questions.

### [e12e](<https://news.ycombinator.com/item?id=50358673>)

> I'd like to see a bit more about how compares to peg or something like ohm/ometa - am I correct assuming you pretty much give up the benefits of a readable grammar as documentation?
>
> Maybe I just need to see something super simple like a calculator with expressions side by side to grasp the trade-off?
>
> https://ohmjs.org/

### [ghusbands](<https://news.ycombinator.com/item?id=50359584>)

> I've written a few Pratt parsers in my time. You don't need a lexer and you can have more parser states than are implied by 'nud' and 'led'. They can be incredibly extensible. For example, if you can parse the expression "{a:1, b:2}" then you might naturally have an Expr state (nud), a Between state (led) and a DictKey state; that might initially accept just an identifier and a colon before recursing into Expr state, but you could later add dynamic expressions, perhaps via a macro, to support [expr] as a key.

### [ogogmad](<https://news.ycombinator.com/item?id=50368797>)

> "Pratt can't parse statements" - can't you treat ';' as an operator whose meaning is "then"? You can then read "DOTHIS(); DOTHAT()" as an expression.

### [direwolf20](<https://news.ycombinator.com/item?id=50359789>)

> Is this the same algorithm commonly known as "recursive descent" parsing and one of the oldest parsing algorithms? The array index example is just recursive descent and the expression parsing is recursive descent with abstracted operators instead of a parsing function per precedence level.
>
> GCC used to use a type of parser generator but switched to recursive descent because the C language is just a little bit too dynamic to make it work well (EG typedefs). They specifically cited the advantage that because you are writing actual code to parse each production rule, you can break the conventions when needed.

---

## Cite

- Page: https://zeli.app/story/50357457
- Date: 2026-11-03
- Source: vinipsmaker.github.io (https://vinipsmaker.github.io/blog/article/pratt-parsing-is-a-black-box/)
- Hacker News: https://news.ycombinator.com/item?id=50357457

## Other languages

- zh: https://zeli.app/zh/story/50357457 · markdown: https://zeli.app/zh/story/50357457.md
- ja: https://zeli.app/ja/story/50357457 · markdown: https://zeli.app/ja/story/50357457.md
- ko: https://zeli.app/ko/story/50357457 · markdown: https://zeli.app/ko/story/50357457.md
- de: https://zeli.app/de/story/50357457 · markdown: https://zeli.app/de/story/50357457.md
- es: https://zeli.app/es/story/50357457 · markdown: https://zeli.app/es/story/50357457.md
- ru: https://zeli.app/ru/story/50357457 · markdown: https://zeli.app/ru/story/50357457.md
