Skip to main content

Simple, Functional, Sound and Complete Parsing for All Context-Free Grammars

  • Conference paper
Certified Programs and Proofs (CPP 2011)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 7086))

Included in the following conference series:

Abstract

Parsers for context-free grammars can be implemented directly and naturally in a functional style known as “combinator parsing”, using recursion following the structure of the grammar rules. However, naive implementations fail to terminate on left-recursive grammars, and despite extensive research the only complete parsers for general context-free grammars are constructed using other techniques such as Earley parsing. Our main contribution is to show how to construct simple, sound and complete parser implementations directly from grammar specifications, for all context-free grammars, based on combinator parsing. We then construct a generic parser generator and show that generated parsers are sound and complete. The formal proofs are mechanized using the HOL4 theorem prover. Memoized parsers based on our approach are polynomial-time in the size of the input. Preliminary real-world performance testing on highly ambiguous grammars indicates our parsers are faster than those generated by the popular Happy parser generator.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Happy, a parser generator for Haskell, http://www.haskell.org/happy/

  2. Barthwal, A., Norrish, M.: Verified, Executable Parsing. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 160–174. Springer, Heidelberg (2009)

    Chapter  Google Scholar 

  3. Danielsson, N.A.: Total parser combinators. In: Hudak, P., Weirich, S. (eds.) ICFP, pp. 285–296. ACM (2010)

    Google Scholar 

  4. Earley, J.: An efficient context-free parsing algorithm. Commun. ACM 13(2), 94–102 (1970)

    Article  MATH  Google Scholar 

  5. Ford, B.: Packrat parsing: simple, powerful, lazy, linear time, functional pearl. In: ICFP 2002: Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming, New York, NY, USA, vol. 37/9, pp. 36–47. ACM (2002)

    Google Scholar 

  6. Frost, R.A., Hafiz, R., Callaghan, P.: Parser Combinators for Ambiguous Left-Recursive Grammars. In: Hudak, P., Warren, D.S. (eds.) PADL 2008. LNCS, vol. 4902, pp. 167–181. Springer, Heidelberg (2008)

    Chapter  Google Scholar 

  7. Frost, R.A., Hafiz, R., Callaghan, P.C.: Modular and efficient top-down parsing for ambiguous left-recursive grammars. In: IWPT 2007: Proceedings of the 10th International Conference on Parsing Technologies, Morristown, NJ, USA, pp. 109–120. Association for Computational Linguistics (2007)

    Google Scholar 

  8. Hafiz, R., Frost, R.A.: Lazy Combinators for Executable Specifications of General Attribute Grammars. In: Carro, M., Peña, R. (eds.) PADL 2010. LNCS, vol. 5937, pp. 167–182. Springer, Heidelberg (2010)

    Chapter  Google Scholar 

  9. Hutton, G.: Higher-order functions for parsing. J. Funct. Program. 2(3), 323–343 (1992)

    Article  MathSciNet  MATH  Google Scholar 

  10. Kasami, T.: An efficient recognition and syntax analysis algorithm for context-free languages. Technical Report AFCRL-65-758, Air Force Cambridge Research Laboratory, Bedford, Massachusetts (1965)

    Google Scholar 

  11. Koprowski, A., Binsztok, H.: TRX: A Formally Verified Parser Interpreter. In: Gordon, A.D. (ed.) ESOP 2010. LNCS, vol. 6012, pp. 345–365. Springer, Heidelberg (2010)

    Chapter  Google Scholar 

  12. Kuno, S.: The predictive analyzer and a path elimination technique. Commun. ACM 8(7), 453–462 (1965)

    Article  MATH  Google Scholar 

  13. Leroy, X.: Formal verification of a realistic compiler. Communications of the ACM (April 2009)

    Google Scholar 

  14. Pratt, V.R.: Top down operator precedence. In: Proceedings ACM Symposium on Principles Prog. Languages (1973)

    Google Scholar 

  15. Ridge, T.: Simple, functional, sound and complete parsing for all context-free grammars (2010) unpublished draft, http://www.cs.le.ac.uk/~tr61

  16. Tomita, M.: Efficient Parsing for Natural Language: A Fast Algorithm for Practical Systems. Kluwer, Boston (1986)

    Book  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2011 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Ridge, T. (2011). Simple, Functional, Sound and Complete Parsing for All Context-Free Grammars. In: Jouannaud, JP., Shao, Z. (eds) Certified Programs and Proofs. CPP 2011. Lecture Notes in Computer Science, vol 7086. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-25379-9_10

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-25379-9_10

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-25378-2

  • Online ISBN: 978-3-642-25379-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics