Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is packrat parsing?

I know and use bison/yacc. But in parsing world, there's a lot of buzz around packrat parsing.

What is it? Is it worth studing?

like image 600
Łukasz Lew Avatar asked Sep 11 '09 12:09

Łukasz Lew


People also ask

What is a recursive descent parser and how does it work?

Recursive descent is a top-down parsing technique that constructs the parse tree from the top and the input is read from left to right. It uses procedures for every terminal and non-terminal entity. This parsing technique recursively parses the input to make a parse tree, which may or may not require back-tracking.


1 Answers

Packrat parsing is a way of providing asymptotically better performance for parsing expression grammars (PEGs); specifically for PEGs, linear time parsing can be guaranteed.

Essentially, Packrat parsing just means caching whether sub-expressions match at the current position in the string when they are tested -- this means that if the current attempt to fit the string into an expression fails then attempts to fit other possible expressions can benefit from the known pass/fail of subexpressions at the points in the string where they have already been tested.

like image 98
James Avatar answered Nov 13 '22 01:11

James