A parsing machine for PEGs

  • Authors:
  • Sérgio Medeiros;Roberto Ierusalimschy

  • Affiliations:
  • PUC-Rio, Rio de Janeiro, Brazil;PUC-Rio, Rio de Janeiro, Brazil

  • Venue:
  • DLS '08 Proceedings of the 2008 symposium on Dynamic languages
  • Year:
  • 2008

Quantified Score

Hi-index 0.00

Visualization

Abstract

Parsing Expression Grammar (PEG) is a recognition-based foundation for describing syntax that renewed interest in top-down parsing approaches. Generally, the implementation of PEGs is based on a recursive-descent parser, or uses a memoization algorithm. We present a new approach for implementing PEGs, based on a virtual parsing machine, which is more suitable for pattern matching. Each PEG has a corresponding program that is executed by the parsing machine, and new programs are dynamically created and composed. The virtual machine is embedded in a scripting language and used by a patternmatching tool. We give an operational semantics of PEGs used for pattern matching, then describe our parsing machine and its semantics. We show how to transform PEGs to parsing machine programs, and give a correctness proof of our transformation.