expr
pratt-parser-blog-code
expr | pratt-parser-blog-code | |
---|---|---|
1 | 2 | |
5 | 28 | |
- | - | |
6.1 | 0.0 | |
12 months ago | over 2 years ago | |
Rust | TypeScript | |
- | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
expr
-
Pratt Parsers: Expression Parsing Made Easy
I had to write an expression parser recently and found the number of names for essentially the same algorithm very confusing. There's Pratt parsing, precedence climbing, and shunting yard. But really they're all the same algorithm.
Pratt parsing and precedence climbing are the same except one merges left/right associativity precedence into a single precedence table (which makes way more sense). Shunting yard is the same as the others except it's iterative instead of recursive, and it seems like common implementations omit some syntax checking (but there's no reason you have to omit it).
Here's what I ended up with:
https://github.com/Timmmm/expr
I had to write that because somewhat surprisingly I couldn't find an expression parser library that supports 64-bit integers and bools. Almost all of them only do floats. Also I needed it in C++ - that library was a prototype that I later translated into C++ (easier to write in Rust and then translate).
pratt-parser-blog-code
-
Pratt Parsers: Expression Parsing Made Easy
Some time ago I went down a fascinating rabbit hole on Pratt parsers while writing a math expression evaluator. In addition to the OP and above-linked article, I found the following helpful.
- How Desmos Uses Pratt Parsers (2018) - TypeScript - https://engineering.desmos.com/articles/pratt-parser/ - Source: https://github.com/desmosinc/pratt-parser-blog-code
- Simple But Powerful Pratt Parsing (2020) - Rust - https://matklad.github.io/2020/04/13/simple-but-powerful-pra... - Source: https://github.com/matklad/minipratt
- Building a tiny little broken calculator with parser combinators
What are some alternatives?
minipratt
RollDice-Discord
PrattParse - Pratt parser builder in TypeScript (along with simple tokenizer)
WebBS - A toy language that compiles to WebAssembly
npeg - PEGs for Nim, another take
fur