# Pratt parsing finally clicked for me once I connected it to the shunting yard algorithm

Original title: Writing about pratt parsing so I remember it

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

▲ 84 · by [dverlaeckt80](<https://news.ycombinator.com/user?id=dverlaeckt80>) · 💬 9
[original](<https://www.unix.dog/~yosh/blog/2026-10-25_pratt-parsing.html>) · [HN discussion](<https://news.ycombinator.com/item?id=50255177>)

## Summary

A hobbyist builds a C expression parser and works through Pratt parsing using Pratt's original paper and Crafting Interpreters. The key insight: Pratt parsing is just shunting yard with the operator stack replaced by the call stack. The post walks through a minimal shunting yard implementation, then shows how the same parser becomes trivially extensible to parentheses, prefix operators, and postfix operators.

## Key quote

> The main transformation that turns the shunting yard algorithm into a pratt parser is: instead of using an explicit stack for operators, using the call stack to enter subexpressions as operators need them.

## HN discussion (9 comments)

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

> Could I suggest also looking at a sed-inspired parsing language
>
> (a DSL) which is called nom and is documented at http://www.nomlang.org
>
> An example script for parsing symbolic expressions is at
>
> http://www.nomlang.org/eg/maths.parse.pss and another which turns the
>
> expressions into LaTeX is /eg/maths.tolatex.pss
>
> Nom may seem quite verbose. I have written another language (which compiles
>
> to nom) which I call Syntagma. The syntax of syntagma is much closer to 
>
> EBNF but also has powerful additions, such as a "lookahead" syntax, a 
>
> negated lookahead syntax (eg: "parse this as an expression if it is not
>
> followed by a multiply operator"). Also, Syntagma has a "condition" syntax, 
>
> meaning that a parse rule will only reduce if the attributes of the 
>
> parse tokens match certain conditions.
>
> An example of an expression parser written in Syntagma is at
>
> http://www.nomlang.org/syntagma/eg/expr.sta  This is much more succinct 
>
> than the equivalent nom script. The script /syntagma/eg/expr.toforth.sta
>
> converts symbolic expressions (and assignments) into Forth.
>
> Parsing is an interesting topic, but I feel that it is quite difficult
>
> or non-intuitive with some of the traditional tools and methods (at 
>
> least for me).

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

> Personally I never found the shunting yard algorithm very intuitive at all.
>
> A recursive descent parser makes much more sense to me.

---

## Cite

- Page: https://zeli.app/story/50255177
- Date: 2026-10-27
- Source: unix.dog (https://www.unix.dog/~yosh/blog/2026-10-25_pratt-parsing.html)
- Hacker News: https://news.ycombinator.com/item?id=50255177

## Other languages

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