Live data from Hacker News

Pratt Parsers: Expression Parsing Made Easy

journal.stuffwithstuff.com

1–10 of 21 posts

Re: Pratt Parsers: Expression Parsing Made Easy

#7
post #2

I slapped together a crude lexer that works and we’ll just pretend that tokens are raining down from heaven or something. This perfectly describes all parsing discussions and papers I've read. I love it.

"I have a truly marvelous demonstration of this proposition which this margin is too small to contain."

Re: Pratt Parsers: Expression Parsing Made Easy

#8
post #6

I believe this algorithm is also known as "precedence climbing", and it's the most common way to deal with operator precedence in a recursive-descent parser.

correct.

the pratt parser is just a way of implementing such a parser.

to be technical, it is a form of left-corner parsing

Re: Pratt Parsers: Expression Parsing Made Easy

#10
post #6

I believe this algorithm is also known as "precedence climbing", and it's the most common way to deal with operator precedence in a recursive-descent parser.

I'd say that having a single production for each precedence level is a more common technique in recursive descent, but it that can be slow because every factor needs to be parsed by recursing through all precedence levels. This technique avoids that, and can parse factors straight away before going into the priority checking loop.

Delphi uses this parsing method for expressions, and is one of the reasons it's so fast at compiling.

Post reply on HN