89 points · by jashkenas · 15y ago · 20 comments
[sorry for the plug, but I think my tutorial is more comprehensive in terms of explaining how the thing actually works]
For example, the "(" token handles grouping in prefix position and function calls in infix, and those don't have anything to do with each other, so I split out PrefixParselets and InfixParselets into entirely separate dictionaries.
This perfectly describes all parsing discussions and papers I've read. I love it.
Edit, I also have a generalized version that can take pretty much any input and any output (F#) here: https://github.com/fholm/Vaughan
Good post. I need to ruminate on this some more but it might well apply to something I'm working on.
Delphi uses this parsing method for expressions, and is one of the reasons it's so fast at compiling.
However, I'd be skeptical that the parser is one of the main reasons for its fast compile times. In my experience, parsing is really a tiny amount of compilation time. The VB.NET compiler, for example, uses the same parsing technique, and it is ... "not fast" at compiling. It spends most of its time binding symbols.
The parser (or more accurately, the lexer) is the bit of the compiler which ultimately limits its performance, because it needs to see every character of the source. The compiler can never be faster than linear in the length of its input. Metrics on the Delphi compiler actually show that string hashing is the hottest piece of code, and that's already optimized about as far as it can go.
the pratt parser is just a way of implementing such a parser.
to be technical, it is a form of left-corner parsing