Re:Pratt parsing is a black box
by ogogmad on Wednesday November 04, 2026 @12:31PM
(#50368797)
"Pratt can't parse statements" - can't you treat ';' as an operator whose meaning is "then"? You can then read "DOTHIS(); DOTHAT()" as an expression.
[ Parent
| on HN ]
Re:Pratt parsing is a black box
by vinipsmaker on Wednesday November 04, 2026 @12:52PM
(#50369110)
You need to forbid stuff such as:
return return 1;
return itself isn't an expression (it's a statement) so it can't be used in places that expect expressions (such as the "argument" to return itself).However extending Pratt parsing to handle this case is trivial: https://vinipsmaker.github.io/blog/article/statements-in-pra...
It's still an extension so not really pure Pratt parsing IMO (other practitioners of Pratt parsing disagree with me).