conv.

All stories
TechQuiet 8d · day 10

Vini Psmaker argues Pratt parsing tutorials miss the point

A blog post argues that most Pratt parsing tutorials focus on implementation over the conceptual framework that actually matters.

What to know

  • Most Pratt parsing tutorials focus on algorithm implementation rather than the conceptual framework that matters for practical use.
  • The core idea—"what do we expect to see to the left of a token?"—is more valuable than memorizing the 9-line code snippet.
  • Pratt parsing has remained unchanged since 1973 and is best approached as a mindset for thinking about parsing, similar to how developers use quicksort without understanding its internals.
most voices

Pratt parsing's value lies in the conceptual framework, not implementation mastery.

  • “I used Pratt parsing in the compiler for a macro-heavy language…Pratt fundamentally changed the design of my language by allowing metaprogramming stuff that I never dreamed of.”

    vinipsmaker · Lobsters ↗
some voices

The mutual recursion between nud() and led() functions is a critical technical detail that shouldn't be overlooked.

  • “In the opening code snippet, I think a VERY important point is that both `nud()` and `led()` will typically call back into `expression()` (after the Pratt logic dispatches to the right one).”

    andyc · Lobsters ↗

Vini Psmaker Blog post author, compiler developerDouglas Crockford Parser theorist (cited)

Vini Psmaker argues Pratt parsing tutorials miss the point
compilers,plt

How it unfolded 8 developments, newest first · click a bar or a number to jump postscomments

Peak 7 pieces in 3h at Nov 1, 12 PM; 24 pieces over 10 days (1 article · 6 posts · 17 comments) Nov 1, 12 PM — 7 pieces · 1 post · 6 comments — Lobsters 7Nov 1, 3 PM — 2 pieces · 2 comments — Lobsters 2Nov 1, 6 PM — 2 pieces · 2 comments — Lobsters 2Nov 1, 9 PM — quietNov 2, 12 AM — 1 piece · 1 post — Hacker News 1Nov 2, 3 AM — quietNov 2, 6 AM — quietNov 2, 9 AM — quietNov 2, 12 PM — quietNov 2, 3 PM — 1 piece · 1 post — Hacker News 1Nov 2, 6 PM — quietNov 2, 9 PM — quietNov 3, 12 AM — quietNov 3, 3 AM — 1 piece · 1 post — Hacker News 1Nov 3, 6 AM — quietNov 3, 9 AM — quietNov 3, 12 PM — 3 pieces · 1 article · 2 posts — Hacker News 1, Mastodon 1, Newswires 1Nov 3, 3 PM — 5 pieces · 5 comments — Hacker News 5Nov 3, 6 PM — 1 piece · 1 comment — Hacker News 1Nov 3, 9 PM — quietNov 4, 12 AM — quietNov 4, 3 AM — quietNov 4, 6 AM — quietNov 4, 9 AM — quietNov 4, 12 PM — 1 piece · 1 comment — Hacker News 1Nov 4, 3 PM — quietNov 4, 6 PM — quietNov 4, 9 PM — quietNov 5, 12 AM — quietNov 5, 3 AM — quietNov 5, 6 AM — quietNov 5, 9 AM — quietNov 5, 12 PM — quietNov 5, 3 PM — quietNov 5, 6 PM — quietNov 5, 9 PM — quietNov 6, 12 AM — quietNov 6, 3 AM — quietNov 6, 6 AM — quietNov 6, 9 AM — quietNov 6, 12 PM — quietNov 6, 3 PM — quietNov 6, 6 PM — quietNov 6, 9 PM — quietNov 7, 12 AM — quietNov 7, 3 AM — quietNov 7, 6 AM — quietNov 7, 9 AM — quietNov 7, 12 PM — quietNov 7, 3 PM — quietNov 7, 6 PM — quietNov 7, 9 PM — quietNov 8, 12 AM — quietNov 8, 3 AM — quietNov 8, 6 AM — quietNov 8, 9 AM — quietNov 8, 12 PM — quietNov 8, 3 PM — quietNov 8, 6 PM — quietNov 8, 9 PM — quietNov 9, 12 AM — quietNov 9, 3 AM — quietNov 9, 6 AM — quietNov 9, 9 AM — quietNov 9, 12 PM — quietNov 9, 3 PM — quietNov 9, 6 PM — quietNov 9, 9 PM — quietYesterday, 12 AM — quietYesterday, 3 AM — quietYesterday, 6 AM — quietYesterday, 9 AM — quietYesterday, 12 PM — quietYesterday, 3 PM — quietYesterday, 6 PM — quietYesterday, 9 PM — quietToday, 12 AM — quietToday, 3 AM — quietToday, 6 AM — quietToday, 9 AM — quietToday, 12 PM — quietToday, 3 PM — quietToday, 6 PM — quiet 1–8
Nov 2Nov 3Nov 4Nov 5Nov 6Nov 7Nov 8Nov 9yesterdaynow · 7:24 PM ET
  1. 8

    Conartist6 clarifies BABLR as push parser with LR mechanics

    A Lobsters commenter clarifies that BABLR is actually a push parser held by grammar control, with LR semantics and special shift instruction handling for infix grammars, not a Pratt parser.

    • > Is it a pratt parser? No. Briefly skimming that file (I spent a few minutes trying to chase definitions across repos before I gave up), it _looks_ like a conventional recursive-descent pull parser, where pulling is implemented via generators. You could also be using the generators for backtracking but I don't see any evidence of that in this…

      pervognsencompilers,plt10d ago4▲view on Lobsters ↗
    2 more of the top 3 · 9 posts in this stretch
    • Tangential - on the 'use [] instead of <>' advice that you referenced in the post, I wish more languages would experiment with making types first class values that just get passed in regular () braces instead.With erased static types, you can do arbitrary operations on types-as-values at compile time and just compile the static result into the…

      p1neconeHacker News8d agoview on Hacker News ↗
    • It's actually a push parser though! The thread of control is held by the grammar not the core. Wherever you see `eatMatch` parsing can backtrack, but otherwise it's LR. It uses a special shift instruction to handle infix grammars.

      conartist6compilers,plt9d ago2▲view on Lobsters ↗
    all of them →
  2. 7

    Vinipsmaker acknowledges parsing philosophy alignment

    The post author responds to a fellow parser expert, noting that they discovered their writing after already developing their own compiler along similar lines and admiring their approach to parsing problems.

    “from any person alive, I think you're the one with the parsing mindset closest to my own…”
    — vinipsmaker
    • I only found/stopped to read/paid attention to your blogposts on the topic of Pratt parsing after my project/language was already deep on “Pratt rails”, but I must say... from any person alive, I think you're the one with the parsing mindset closest to my own (when it comes to parsing problems). This time I'll probably copy your design on eggexes…

      vinipsmakercompilers,plt10d ago4▲view on Lobsters ↗
  3. 6

    Parser developer andyc highlights mutual recursion in Pratt implementations

    A Lobsters commenter with prior parsing writing emphasizes that both nud() and led() functions typically call back into expression(), making Pratt parsing fundamentally mutually recursive like recursive descent.

    “In the opening code snippet, I think a VERY important point is that both `nud()` and `led()` will typically call back into `expression()` (after the Pratt logic dispatches to the right one).”
    — andyc, Lobsters commenter, parser developer · source
    • I'm glad to see more explorations of Pratt parsing :-) And thanks for referring to previous writing, including my own! In the opening code snippet, I think a VERY important point is that both `nud()` and `led()` will typically call back into `expression()` (after the Pratt logic dispatches to the right one). There's no getting around that…

      andyccompilers,plt10d ago10▲view on Lobsters ↗
  4. 5

    Conartist6 asks for parser classification of BABLR

    A Lobsters commenter questions whether BABLR (a grammar-based parser) should be categorized as a Pratt parser, sparking technical discussion about parser taxonomy.

    • I still wish to know: what would people categorize BABLR as? Is it a pratt parser?

      conartist6compilers,plt10d ago1▲view on Lobsters ↗
    1 more of the top 2 · 2 posts in this stretch
    • Looks like something to do with Typst and its "zebraw" package:

      conartist6compilers,plt10d ago1▲view on Lobsters ↗
    all of them →
  5. 4

    Technical issue notedCode blocks repeated four times in rendering

    A Lobsters commenter points out that the blog post's code blocks appear repeated four times due to what appears to be a Typst HTML styling issue, affecting both Chrome reading mode and Firefox.

    • There are in fact four complete copies of each code block as it looks the typst html styling in use seems to use four separate divs each containing the full text content and then do some selective display or something of them for color schemes and stuff. Chrome reading mode also behaves the same rendering all four copies.

      abeyercompilers,plt10d ago4▲view on Lobsters ↗
    1 more of the top 2 · 2 posts in this stretch
    • I don't know what could possibly be causing this, but in Firefox's reading mode the contents of every code block are repeated four times.

      hjvtcompilers,plt10d ago1▲view on Lobsters ↗
    all of them →
  6. 3

    Pervognsen recommends Lean's approach to self-extensible parsing

    A Lobsters commenter points to Lean's implementation of Pratt parsing in self-extensible languages, noting how dependent typing forces single-pass execution with natural synchronization boundaries.

    • For Pratt parsing as a component of a self-extensible language like this, it's worth checking out what Lean does. Most dependently typed languages require explicit forward declarations and other things that already force them to run in a single pass at the top level. In Lean's case, the top-level granularity is one command-like item executed in a…

      pervognsencompilers,plt10d ago19▲view on Lobsters ↗
  7. 2

    Psmaker shares personal experience using Pratt in compiler design

    In a Lobsters comment, Psmaker describes using Pratt parsing in a macro-heavy compiler project for nearly a year, noting that it fundamentally changed the language design by enabling metaprogramming capabilities.

    “Pratt fundamentally changed the design of my language by allowing metaprogramming stuff that I never dreamed of.”
    — vinipsmaker
    • I used Pratt parsing in the compiler for a macro-heavy language that I've been developing for almost a year before finally sitting down on my chair to write my thoughts on Pratt parsing. The code is closed right now because I don't want LLMs training on my code before the public release for 0.1, but what I can say is that Pratt fundamentally…

      vinipsmakercompilers,plt10d ago8▲view on Lobsters ↗
  8. 1

    Vini Psmaker publishes essay on Pratt parsing pedagogy

    A blog post titled "Pratt parsing is a black box" argues that most tutorials focus on the algorithm's implementation rather than the conceptual framework behind it. The post asserts that understanding Pratt as a mindset about parsing is more important than memorizing code.

    “And here's a secret: that's the least important thing you need to understand about Pratt's. In fact, you don't need to understand this piece at all!”
    — Vini Psmaker
    1. first by HN Frontpage, 8d ago

What people are saying 6 voices from 1 site · best of 17 · verbatim