DCGs + memoing = packrat parsing but is it worth it?

  • Authors:
  • Ralph Becket;Zoltan Somogyi

  • Affiliations:
  • NICTA and Department of Computer Science and Software Engineering, The University of Melbourne, Parkville, Victoria, Australia;NICTA and Department of Computer Science and Software Engineering, The University of Melbourne, Parkville, Victoria, Australia

  • Venue:
  • PADL'08 Proceedings of the 10th international conference on Practical aspects of declarative languages
  • Year:
  • 2008

Quantified Score

Hi-index 0.00

Visualization

Abstract

Packrat parsing is a newly popular technique for efficiently implementing recursive descent parsers. Packrat parsing avoids the potential exponential costs of recursive descent parsing with backtracking by ensuring that each production rule in the grammar is tested at most once against each position in the input stream. This paper argues that (a) packrat parsers can be trivially implemented using a combination of definite clause grammar rules and memoing, and that (b) packrat parsing may actually be significantly less efficient than plain recursive descent with backtracking, but (c) memoing the recognizers of just one or two nonterminals, selected in accordance with Amdahl's law, can sometimes yield speedups. We present experimental evidence to support these claims.