10.1145/1408681.1408683acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
research-article

A parsing machine for PEGs

Published:08 July 2008Publication History

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.

References

  1. B. Ford. Packrat parsing:: simple, powerful, lazy, linear time, functional pearl. SIGPLAN Not., 37(9):36--47, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. D. P. Friedman, C. T. Haynes, and M. Wand. Essentials of programming languages (2nd ed.). Massachusetts Institute of Technology, Cambridge, MA, USA, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. G. Hutton and E. Meijer. Monadic Parsing in Haskell. Journal of Functional Programming, 8(4):437--444, July 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. R. Ierusalimschy. Programming in Lua, Second Edition. Lua.Org, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. R. Ierusalimschy. A Text Pattern-Matching Tool based on Parsing Expression Grammars. Software - Practice and Experience, 2008 (to appear). Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. D. E. Knuth. Top-down syntax analysis. Acta Inf., 1:79--110, 1971.Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle Scholar
  11. LPEG: Parsing Expression Grammars For Lua. Available at http://www.inf.puc-rio.br/~roberto/lpeg,2008. Visited on April 2008.Google ScholarGoogle Scholar
  12. peg/leg - recursive-descent parser generators for C. Available at http://piumarta.com/software/peg/, 2008. Visited on June 2008.Google ScholarGoogle Scholar
  13. R. R. Redziejowski. Parsing expression grammar as a primitive recursive-descent parser with backtracking. Fundamenta Informaticae, 3--4(79):513--524, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. K. Thompson. Programming techniques: Regular expression search algorithm. Commun. ACM, 11(6):419--422, 1968.Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A parsing machine for PEGs

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!