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.
- B. Ford. Packrat parsing:: simple, powerful, lazy, linear time, functional pearl. SIGPLAN Not., 37(9):36--47, 2002. Google Scholar
Digital Library
- B. Ford. Parsing expression grammars: a recognition-based syntactic foundation. In POPL '04: Proceedings of the 31st ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 111--122, New York, NY, USA, 2004. ACM. Google Scholar
Digital Library
- D. P. Friedman, C. T. Haynes, and M. Wand. Essentials of programming languages (2nd ed.). Massachusetts Institute of Technology, Cambridge, MA, USA, 2001. Google Scholar
Digital Library
- R. Grimm. Better extensibility through modular syntax. In PLDI '06: Proceedings of the 2006 ACM SIGPLAN conference on Programming language design and implementation, pages 38--51, New York, NY, USA, 2006. ACM. Google Scholar
Digital Library
- G. Hutton and E. Meijer. Monadic Parsing in Haskell. Journal of Functional Programming, 8(4):437--444, July 1998. Google Scholar
Digital Library
- R. Ierusalimschy. Programming in Lua, Second Edition. Lua.Org, 2006. Google Scholar
Digital Library
- R. Ierusalimschy. A Text Pattern-Matching Tool based on Parsing Expression Grammars. Software - Practice and Experience, 2008 (to appear). Google Scholar
Digital Library
- R. Ierusalimschy, L. H. de Figueiredo, and W. C. Filho. Lua - an extensible extension language. Software - Practice and Experience, 26(6):635--652, 1996. Google Scholar
Digital Library
- D. E. Knuth. Top-down syntax analysis. Acta Inf., 1:79--110, 1971.Google Scholar
Digital Library
- D. J. P. Leijen and H. J. M. Meijer. Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-35, Department of Information and Computing Sciences, Utrecht University, 2001.Google Scholar
- LPEG: Parsing Expression Grammars For Lua. Available at http://www.inf.puc-rio.br/~roberto/lpeg,2008. Visited on April 2008.Google Scholar
- peg/leg - recursive-descent parser generators for C. Available at http://piumarta.com/software/peg/, 2008. Visited on June 2008.Google Scholar
- R. R. Redziejowski. Parsing expression grammar as a primitive recursive-descent parser with backtracking. Fundamenta Informaticae, 3--4(79):513--524, 2007. Google Scholar
Digital Library
- K. Thompson. Programming techniques: Regular expression search algorithm. Commun. ACM, 11(6):419--422, 1968.Google Scholar
Digital Library
- A. Warth and I. Piumarta. Ometa: an object-oriented language for pattern matching. In DLS '07: Proceedings of the 2007 symposium on Dynamic languages, pages 11--19, New York, NY, USA, 2007. ACM. Google Scholar
Digital Library
Index Terms
A parsing machine for PEGs




Comments