
Making a Pratt Parser Generator - todsacerdoti
https://www.robertjacobson.dev/designing-a-pratt-parser-generator
======
Nycto
My go to article for Pratt parsing:

[http://journal.stuffwithstuff.com/2011/03/19/pratt-
parsers-e...](http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-
expression-parsing-made-easy/)

------
jopsen
Pratt-parsers is a very underrated style of parsing.

Years ago when I was at Mozilla we built PrattParser utils in JS:
[https://github.com/taskcluster/json-e/blob/386ae415d807eb066...](https://github.com/taskcluster/json-e/blob/386ae415d807eb066a603007253fd9d316dadc1b/src/interpreter.js#L317)

It probably had short comings, because it's been rewritten since (I haven't
kept up).

But with a few rules and simple functions a pratt parser is rather intuitive,
and easy to write and port to other languages.

I'd be very curious to see the next article :)

------
wirthjason
Thorsten Ball’s “Writing an Interpreter in Go” has a very in-depth walkthrough
of building a Pratt parser. It’s a very good read/tutorial.

Maybe it’s just me but it seems there’s a lot of language design coming out
recently. E.g. Bob Nystrom has “Crafting Interpreters.” It really like that
language design and parsing gets more attention, which is great because it’s
fascinating stuff.

~~~
mamp
My favourite article on Pratt parsing, it’s in Rust but easy to port to any
language:

[https://matklad.github.io/2020/04/13/simple-but-powerful-
pra...](https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-
parsing.html)

~~~
RobertJacobson
Matklad follows Norvell's excellent exposition in these two articles pretty
closely:

[http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm)

[http://www.engr.mun.ca/~theo/Misc/pratt_parsing.htm](http://www.engr.mun.ca/~theo/Misc/pratt_parsing.htm)

Matklad's stuff is really great. I wish he had cited Norvell, though.

------
oso2k
Hopefully Robert Jacobson sees this, but, the TFA uses the word "donation"
when Pratt used "denotation." Just a couple small typos.

~~~
RobertJacobson
I have easily read more than a dozen articles over the years on this parsing
strategy, including Pratt's original paper, and in every case I have read
"donation." But you are 100% right! All of my sources actually use denotation.
MY MIND IS FREAKING BLOWN.

I am going to go meditate on the subjectivity of my reality. If I am wrong
about this, what else am I wrong about?

~~~
oso2k
LOL. I don't think it's that serious. Maybe it's the Berenstain Bears Effect,
Mandela Effect, Glitch in the Matrix, or ... a slight lack of your favorite
morning pick me up. :D In any case, looking forward to reading the next
article.

Personally, at some point, I'd like to write a Pratt Parser in C99. I'd like
to explore the one sentiment you had that OOP has a negative effect on
understanding Pratt Parsers.

------
olah_1
Can anyone recommend the best parser for human language? Detecting natural
suffixes, etc.

~~~
feminintendo
Google "natural language processing."

Natural languages are highly ambiguous. Using a naive approach like Early's
algorithm can lead to thousands of parse trees for a single sentence.
Probabilistic grammar parsing algorithms attempt to discover the "most likely"
parse tree with respect to a particular statistical model of the language
grammar. As with parsing algorithms for formal languages, different algorithms
make different trade-offs. "Best" only makes sense with respect to a
particular metric: "Best" in what sense?

I personally don't know much about this area beyond what I just said.

