Parsing Expression Grammar as a Primitive Recursive-Descent Parser with Backtracking

  • Authors:
  • Roman R. Redziejowski

  • Affiliations:
  • Giraf's Research. E-mail: roman.redz@swipnet.se

  • Venue:
  • Fundamenta Informaticae - Special Issue on Concurrency Specification and Programming (CS&P)
  • Year:
  • 2007

Quantified Score

Hi-index 0.00

Visualization

Abstract

Two recent developments in the field of formal languages are Parsing Expression Grammar (PEG) and packrat parsing. The PEG formalism is similar to BNF, but defines syntax in terms of recognizing strings, rather than constructing them. It is, in fact, precise specification of a backtracking recursive-descent parser. Packrat parsing is a general method to handle backtracking in recursive-descent parsers. It ensures linear working time, at a huge memory cost. This paper reports an experiment that consisted of defining the syntax of Java 1.5 in PEG formalism, and literally transcribing the PEG definitions into parsing procedures (accidentally, also in Java). The resulting primitive parser shows an acceptable behavior, indicating that packrat parsing might be an overkill for practical languages. The exercise with defining the Java syntax suggests thatmore work is needed on PEG as a language specification tool.