Building a tiny little broken calculator with parser combinators
blog.jfo.click
blog.jfo.click
http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-e...
- 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
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.
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"?