Better names for Pratt parameters
One thing that confuses me about Pratt implementations in general is the arbitrary use of the terms left and right. It's fair to acknowledge that the whole issue solved by operator-precedence parsing is whether a given term/subexpression binds to left or right:
In the example above, does B bind to ♠ or ♦? We must compare their binding powers to know. However, in Pratt, algorithms are recursive and whether a term is left or right depends on the point of view (how deep are you in the callstack?). So… I always found confusing to understand Pratt from this exposition:
Over the months using Pratt, I found it was clearer to me to rename the parameters to:
However the semantic action for a led can retain the name left for its last parameter:
After using Pratt extensively for a language that I've been developing since last year, nud & led were terms that never held me back. Nud & led are the terms that beginners in the Pratt school usually complain about, but introducing new terms for new concepts help to shape your mental model to use the new framework. They put you in the proper state of mind to reason about the problem, and that matters for enabling you to tackle harder problems with more ease. If we were to replace “led” by “binary operator” (as usually done by beginners), it'd hide the fact that leds are also used for postfix operators (and some mistfix ones), and it'd actually preclude you from understating Pratt's power. The changes that I suggest above don't suffer from this problem.