Building a tiny little broken calculator with parser combinators(blog.jfo.click)
blog.jfo.click
Building a tiny little broken calculator with parser combinators
https://blog.jfo.click/building-a-tiny-little-broken-calculator-with-parser-combinators/
8 comments
I believe Pratt, TDOP, and precedence climbing are all just different names for the same technique that involves comparing precedences in a loop. The fact that it's basic principle is so simple is probably what lead to multiple independent reinventions.
If anything, after reading about the aforementioned algorithms, the technique in the article seems to show that using parser combinators is a lot of work for very little gain --- I've read much shorter articles on recursive descent, and those do handle precedence correctly.
If anything, after reading about the aforementioned algorithms, the technique in the article seems to show that using parser combinators is a lot of work for very little gain --- I've read much shorter articles on recursive descent, and those do handle precedence correctly.
What is your complaint re precedence in Pratt parsing? The linked code properly implements precedence fairly trivially.
I think you misunderstood. I'm referring to the original article of this item, not your linked code.
That’s more a critique of the author than the concept - I gave up midway through the article but order combinators remain a useful tool, particularly as a library. To my eyes, the logic here https://github.com/JacksonKearl/RollDice-Discord/blob/master... is much simpler than the equivalent recursive descent code would be. I’d be interested in an article comparing them in greater detail.
I'm a fan of Pratt parsers too. In addition to the article by @munificent you linked above, 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
- 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
To the original author:
Under "Parser Generator":
```
There seems to be a typo: the 2nd "parseA" should really be a "parseB"?
Under "Parser Generator":
```
const parseChar = char =>
input => [
input[0] === char,
input.slice(1, input.length)
];
const parseA = parseChar('A');
const parseA = parseChar('B');
parseA(testString) // [ true, 'bcd123' ]
parseB(testString) // [ false, 'Abcd123' ]
```There seems to be a typo: the 2nd "parseA" should really be a "parseB"?
Thanks, I have fixed it
http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-e...
https://github.com/JacksonKearl/PrattParse