frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Intuiting Pratt Parsing

https://louis.co.nz/2026/03/26/pratt-parsing.html
38•signa11•1d ago

Comments

logdahl•1h ago
Love Pratt parsing! Not a compiler guy, but I've spent way too many hours reflecting on parsing. I remember trying to get though the dragon book so many times and reading all about formal grammar etc. Until I landed on; recursive descent parsing + Pratt for expressions. Super simple technique, and for me is sufficient. I'm sure it doesn't cover all cases, but just for toy languages it feels like we can usually do everything with 2-token lookahead.

Not to step on anyone's toes, I just don't feel that formal grammar theory is that important in practice. :^)

gignico•46m ago
Until you need to do more than all-or-nothing parsing :) see tree-sitter for example, or any other efficient LSP implementation of incremental parsing.
ogogmad•31m ago
Quick other one: To parse infix expressions, every time you see "x·y | (z | w)", find the operator of least binding power: In my example, I've given "|" less binding power than "·". Anyway, this visually breaks the expression into two halves: "x·y" and "(z | w)". Recursively parse those two subexpressions. Essentially, that's it.

The symbols "·" and "|" don't mean anything - I've chosen them to be visually intuitive: The "|" is supposed to look like a physical divider. Also, bracketed expressions "(...)" or "{...}" should be parsed first.

Wikipedia mentions that a variant of this got used in FORTRAN I. You could also speed up my naive O(n^2) approach by using Cartesian trees, which you can build using something suspiciously resembling precedence climbing.

randomNumber7•27m ago
It's not for toy languages. Most big compilers use recursive descent parsing.
signa11•12m ago
> Not to step on anyone's toes, I just don't feel that formal grammar theory is that important in practice. :^)

exactly this ! a thousand times this !

ogogmad•5m ago
I think even the theory of Regular Languages is overdone: You can get the essence of what NFAs are without really needing NFAs. You can get O(n) string matching without formally implementing NFAs, or using any other formal model like regex-derivatives. In fact, thinking in terms of NFAs makes it harder to see how to implement negation (or "complement" if you prefer to call it that) efficiently. It's still only linear time!
priceishere•45m ago
An even simpler way imo, is explicit functions instead of a precedence table, then the code pretty much has the same structure as EBNF.

Need to parse * before +? Begin at add, have it call parse_mul for its left and right sides, and so on.

  parse_mul() {
    left = parse_literal()
    while(is_mul_token()) { // left associative
      right = parse_literal()
      make_mul_node(left, right)
    }
  }

  parse_add() {
    left = parse_mul()
    while(is_add_token()) { // left associative
      right = parse_mul()
      make_add_node(left, right)
    }
  }
Then just add more functions as you climb up the precedence levels.
kryptiskt•32m ago
You lose in versatility, then you can't add user-defined operators, which is pretty easy with a Pratt parser.
randomNumber7•26m ago
I can recommend anyone reading pratts original paper. Its written in a very cool and badass style.

https://dl.acm.org/doi/epdf/10.1145/512927.512931

hyperhello•4m ago
You can either use the stack in an intuitive way, or you can change the tree directly in a somewhat less intuitive way without recursion. Essentially either DF or BF. I don’t see how it matters much anymore with stacks that grow automatically, but it’s good to understand.

Claude Code Unpacked : A visual guide

https://ccunpacked.dev/
556•autocracy101•6h ago•157 comments

CERN levels up with new superconducting karts

https://home.cern/news/news/engineering/cern-levels-new-superconducting-karts
173•fnands•4h ago•46 comments

Intuiting Pratt Parsing

https://louis.co.nz/2026/03/26/pratt-parsing.html
38•signa11•1d ago•10 comments

Show HN: CLI to order groceries via reverse-engineered REWE API (Haskell)

https://github.com/yannick-cw/korb
108•wazHFsRy•2d ago•38 comments

Solar panels at Lidl? Plug-in versions set to appear in shops

https://www.thisismoney.co.uk/money/bills/article-15673955/Solar-panels-Lidl-Plug-versions-set-ap...
29•ZeljkoS•3h ago•34 comments

Wasmer (YC S19) Is Hiring – Rust and DevRel Positions

https://www.workatastartup.com/companies/wasmer
1•syrusakbary•9m ago

Claude Wrote a Full FreeBSD Remote Kernel RCE with Root Shell (CVE-2026-4747)

https://github.com/califio/publications/blob/main/MADBugs/CVE-2026-4747/write-up.md
78•ishqdehlvi•6h ago•24 comments

Chess in SQL

https://www.dbpro.app/blog/chess-in-pure-sql
84•upmostly•2d ago•19 comments

A dot a day keeps the clutter away

https://scottlawsonbc.com/post/dot-system
370•scottlawson•14h ago•101 comments

Show HN: 1-Bit Bonsai, the First Commercially Viable 1-Bit LLMs

https://prismml.com/
292•PrismML•15h ago•118 comments

TinyLoRA – Learning to Reason in 13 Parameters

https://arxiv.org/abs/2602.04118
190•sorenjan•4d ago•23 comments

I Quit. The Clankers Won

https://dbushell.com/2026/04/01/i-quit-the-clankers-won/
10•domysee•3h ago•2 comments

TruffleRuby

https://chrisseaton.com/truffleruby/
143•tosh•3d ago•16 comments

Bring Back MiniDV with This Raspberry Pi FireWire Hat

https://www.jeffgeerling.com/blog/2026/minidv-with-raspberry-pi-firewire-hat/
72•ingve•3d ago•12 comments

In Case of Emergency, Make Burrito Bison 3 (2017)

https://juicybeast.com/2017/08/03/in-case-of-emergency-make-burrito-bison-3/
14•amarcheschi•1d ago•5 comments

MiniStack (replacement for LocalStack)

https://ministack.org/
246•kerblang•15h ago•46 comments

The Claude Code Source Leak: fake tools, frustration regexes, undercover mode

https://alex000kim.com/posts/2026-03-31-claude-code-source-leak/
1224•alex000kim•23h ago•498 comments

Why the US Navy won't blast the Iranians and 'open' Strait of Hormuz

https://responsiblestatecraft.org/iran-strait-of-hormuz/
365•KoftaBob•1d ago•990 comments

Slop is not necessarily the future

https://www.greptile.com/blog/ai-slopware-future
255•dakshgupta•21h ago•410 comments

OpenAI closes funding round at an $852B valuation

https://www.cnbc.com/2026/03/31/openai-funding-round-ipo.html
466•surprisetalk•16h ago•410 comments

6o6 v1.1: Faster 6502-on-6502 virtualization for a C64/Apple II Apple-1 emulator

http://oldvcr.blogspot.com/2026/03/6o6-v11-faster-6502-on-6502.html
11•classichasclass•3d ago•0 comments

Neanderthals survived on a knife's edge for 350k years

https://www.science.org/content/article/neanderthals-survived-knife-s-edge-350-000-years
162•Hooke•10h ago•126 comments

4D Doom

https://github.com/danieldugas/HYPERHELL
222•chronolitus•4d ago•53 comments

Open source CAD in the browser (Solvespace)

https://solvespace.com/webver.pl
341•phkahler•23h ago•104 comments

Digitizing photos from the 1998 Game Boy Camera

https://swiftrocks.com/digitizing-photos-from-the-1998-game-boy-camera
56•rockbruno•3d ago•10 comments

Axios compromised on NPM – Malicious versions drop remote access trojan

https://www.stepsecurity.io/blog/axios-compromised-on-npm-malicious-versions-drop-remote-access-t...
1859•mtud•1d ago•747 comments

Teenage Engineering's PO-32 acoustic modem and synth implementation

https://github.com/ericlewis/libpo32
127•ericlewis•4d ago•26 comments

Ordinary Lab Gloves May Have Skewed Microplastic Data

https://nautil.us/ordinary-lab-gloves-may-have-skewed-microplastic-data-1279386
110•WaitWaitWha•14h ago•43 comments

Analyzing Geekbench 6 under Intel's BOT

https://www.geekbench.com/blog/2026/03/analyzing-geekbench-6-under-intels-bot/
34•hajile•8h ago•13 comments

Remembering Magnetic Memories and the Apollo AGC

https://2earth.github.io/website/20260304.html
10•2earth•4h ago•2 comments