Skip to Main Content
Language Implementation Patterns
book

Language Implementation Patterns

by Terence Parr
December 2009
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 2m
English
Pragmatic Bookshelf
Content preview from Language Implementation Patterns
Pattern 6Memoizing Parser

Purpose

This pattern records partial parsing results during backtracking to guarantee linear parsing performance, at the cost of a small amount of memory.

Memoizing is a form of dynamic programming and lets us avoid reparsing the same input with the same rule. Another name for memoizing recursive-descent parser is packrat parser, a fabulous term coined by Bryan Ford in Packrat parsing:: simple, powerful, lazy, linear time, functional pearl [For02].

Discussion

Without memoization to avoid redundant parsing, backtracking can lead to impractically slow (exponentially complex) parse times. This pattern guarantees linear parse time at the cost of a bit of memory. The extra memory is well worth the gain in parsing speed. I’ve ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Implementation Patterns

Implementation Patterns

Kent Beck

Publisher Resources

ISBN: 9781680500097Errata Page