Pratt Parsers: Expression Parsing Made Easy – journal.stuffwithstuff.com
Every now and then, I stumble onto some algorithm or idea that’s so clever and such a perfect solution to a problem that I feel like I got smarter or gained a new superpower just by learning it. Heaps were one, just about the only thing I got out of my truncated CS education. I recently stumbled onto another: Pratt or “top-down operator precedence” parsers. When you’re writing a parser, recursive descent is as easy as spreading peanut butter. It excels when you can figure out what to parse based on the next bit of code you’re looking at. That’s usually true at the declaration and statement levels of a language’s grammar since most syntax there starts with keywords—class, if, for, while, etc. Parsing gets trickier when you get to expressions. When it comes to infix operators like +, postfix ones like ++, and even mixfix expressions like ?:, it can be hard to tell what kind of expression you’re parsing until you’re halfway through it. You can do this with recursive descent, but it’s a ch
Pratt Parsers: Expression Parsing Made Easy Every now and then, I stumble onto some algorithm or idea that's so clever and such a perfect solution to a problem that I feel like I got smarter or gained a new superpower just by learning it. Heaps were one, just about the only thing I got out of my truncated CS education. I recently stumbled onto another: Pratt or "top-down operator precedence" parsers. When you're writing a parser, recursive descent is as easy as spreading peanut butter. It excels when you can figure out what to parse based on the next bit of code you're looking at. That's usual
Explore this link on the map →related reading
- Laurence Tratt: Which Parsing Approach?tratt.net
- Shunting yard algorithm - Wikipediaen.wikipedia.org
- Parsing Expressions · Crafting Interpreterscraftinginterpreters.com
- Reading 12: Regular Expressions & Grammarsweb.mit.edu
- 2. Kaleidoscope: Implementing a Parser and AST — LLVM 23.0.0git documentationllvm.org
- Infix to Postfix Expression - GeeksforGeeksgeeksforgeeks.org
- Reading 19: Parsersweb.mit.edu
- Problem Set 3: Memelyweb.mit.edu
- Representing Code · Crafting Interpreterscraftinginterpreters.com
- Structure and Interpretation of Computer Programsmitp-content-server.mit.edu
- 4 A First Taste of Desugaringcs.brown.edu
- Reading 19: Little Languagesweb.mit.edu