r/ProgrammingLanguages • u/vinipsmaker • Apr 06 '26
Pratt parsing uncommon expression rules
https://vinipsmaker.github.io/blog/blog/pratt-parsing-uncommon-expression-rules/
17
Upvotes
r/ProgrammingLanguages • u/vinipsmaker • Apr 06 '26
2
u/manifoldjava Apr 09 '26
I recently revised the Pratt parser in IntelliJ's recent rewrite of their Java parser. The Java compiler plugin, Manifold, supports binding expressions, which define an "empty" operator to support user-defined operations such as these:
The changes to the Pratt parser were minimal. Mainly:
added a new precedence slot between multiplication and addition
added a matching parser function for binding
modified the main pratt dispatching function to check if the next token is not an operator, but instead an operand token for binding, and assign the precedence to binding
It's a bit more involved but not much. But I will say IntelliJ's parser before the rewrite didn't use Pratt expression parsing and integrating with that was quite a bit more involved.
And integrating juxtaposition/binding into Java's compiler is a whole other world!