News for hackers. Stuff that matters.
Re:Pratt Parsers: Expression Parsing Made Easy (2011) by kragen on Saturday January 20, 2024 @11:40AM (#39069374)
i feel like maybe this is messier if the parser you're trying to escape from is lalr or something else bottom-up?
Re:Pratt Parsers: Expression Parsing Made Easy (2011) by vidarh on Saturday January 20, 2024 @05:29PM (#39073110)
It really depends on how easy it is to determine the handover points. If the grammar gives you clear, unambiguous boundaries that don't require much context to determine when to switch, you should be able to switch reasonably easily almost no matter the grammar type.

I agree it's easier to apply this top-down, though - you just call into the other parser and get whatever subexpression back, and you "just" need to have it treat tokens that can't continue an expression as the end of the stream.

E.g. a trivial top down example would be any language where IF/ELSE is not an expression - you might parser IF (condition), then call into a Pratt parser, treat "ELSE" or "END" as terminating the expression, and just continue.

Bottom-up you can still handle grammars that unambiguous fairly easily if the delimiting tokens aren't valid in other contexts, but I suspect you're right you'll get into trouble more easily if the grammars are more complex.

Re:Pratt Parsers: Expression Parsing Made Easy (2011) by kragen on Monday January 22, 2024 @12:53AM (#39086752)
thanks, this is very interesting