r/ProgrammingLanguages • u/vinipsmaker • Apr 25 '26
Pratt parsing is a black box
https://vinipsmaker.github.io/blog/blog/pratt-parsing-is-a-black-box/
29
Upvotes
r/ProgrammingLanguages • u/vinipsmaker • Apr 25 '26
11
u/bl4nkSl8 Apr 25 '26
"Pratt parsing is a black box" really should be changed to
"Pratt parsing is fine as a black box"
I.e. you don't have to understand it to use it (just like most parsers) but it's not that complicated: simpler than PEG or ANTLR etc (imo)
But then I'm using it on my hobby project so I'm a little biased from some experience.
My main attraction to it is that it supports context sensitivity (i.e. you can parse things that change the s tables, like new operators, macro definitions, etc).
1
u/EggplantExtra4946 Apr 30 '26
The Shunting-Yard algorithm implements the same fundamental algorithm than Pratt's algorithm, is easier to understand, is easier to extend.
10
u/vanderZwan Apr 25 '26
I mean, I guess from a certain point of view, but that
advance()is not defined locally, nor istokenor its methods and properties being invoked or accessed. Isn't this a bit like claiming one can write a parser in one line of code, becaure all I have to do is callparser.parse()and hide all implementation details in that method?I dunno, maybe I'm misunderstanding the point you're actually making but I'm a bit confused by that bit.
8
u/[deleted] Apr 25 '26
[removed] — view removed comment