I've noticed that my November posts on expression parsing with Pratt's algorithm are popular and still drawing readers.
So here's an index of them, with related links.
(1) Pratt Parsing and Precedence Climbing Are the Same Algorithm
After parsing arithmetic in OSH, I noticed that the precedence climbing algorithm is a special case of the earlier Pratt parsing algorithm — but see the update below.
(2) Review of Pratt/TDOP Parsing Tutorials
I reviewed four articles, in order to motivate a different code structure.
(3) Pratt Parsing Without Prototypal Inheritance, Global Variables, Virtual Dispatch, or Java
Crockford deserves credit for reviving Pratt's algorithm, but I think his idiosyncratic style leaked into almost every future exposition of it.
In this article, I explain the code structure I used, with tested and runnable code in my pratt-parsing-demo repo. Summary:
Why? I tend to use classes somewhat formally, either for dependency injection or for maintaining invariants on state. If everything's a class, then nothing is.
(4) Pratt Parsers Can Be Statically Typed
A minor update to correct a misleading notion.
To avoid confusion, I recommended dropping the precedence climbing name in favor of the earlier Pratt parsing name.
After looking at real code, I've changed my view. I would now classify the two top-down algorithms like this:
-5 and
binary x - 2, as well as the tenary operator.