What is packrat parsing?

后端 未结 3 948
灰色年华
灰色年华 2021-01-31 08:30

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?

3条回答
  •  心在旅途
    2021-01-31 09:07

    Pyparsing is a pure-Python parsing library that supports packrat parsing, so you can see how it is implemented. Pyparsing uses a memoizing technique to save previous parse attempts for a particular grammar expression at a particular location in the input text. If the grammar involves retrying that same expression at that location, it skips the expensive parsing logic and just returns the results or exception from the memoizing cache.

    There is more info here at the FAQ page of the pyparsing wiki, which also includes links back to Bryan Ford's original thesis on packrat parsing.

提交回复
热议问题