Skip to main content

Explicitly Recursive Grammar Combinators

A Better Model for Shallow Parser DSLs

  • Conference paper

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 6539))

Abstract

We propose a novel context-free grammar representation for parsing libraries in a pure programming language. Our representation explicitizes the recursion in the grammar, thus avoiding fundamental limitations of the grammar model currently employed by parser combinator libraries. Additionally, we decouple the grammar from its semantic actions using techniques from the Multirec generic programming library. The look and feel of the grammar and semantic actions remain close to traditional EBNF and syntax-directed definitions respectively.

In an accompanying technical report, we demonstrate that our representation supports more declarative implementations of grammar transformations than other work. The ideas described in this paper form the basis for our freely available grammar-combinators parsing library.

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

Buying options

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

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Aho, A.V., Lam, M.S., Sethi, R., Ullman, J.D.: Compilers: Principles, Techniques and Tools, 2nd edn. Addison-Wesley, Reading (2006)

    MATH  Google Scholar 

  2. Johnson, S.C.: YACC. Unix Programmer’s Manual 2b (1979)

    Google Scholar 

  3. Parr, T., Quong, R.: ANTLR: A predicated-LL(k) parser generator. Software: Practice and Experience 25(7), 789–810 (1995)

    Google Scholar 

  4. Swierstra, S., Duponcheel, L.: Deterministic, error-correcting combinator parsers. In: Advanced Functional Programming, pp. 184–207 (1996)

    Google Scholar 

  5. Sabry, A.: What is a purely functional language? JFP 8(1), 1–22 (1998)

    MathSciNet  MATH  Google Scholar 

  6. Sheard, T., Peyton Jones, S.: Template meta-programming for Haskell. SIGPLAN Notices 37(12), 75 (2002)

    Article  Google Scholar 

  7. Yakushev, A., Holdermans, S., Löh, A., Jeuring, J.: Generic programming with fixed points for mutually recursive datatypes. In: ICFP, pp. 233–244 (2009)

    Google Scholar 

  8. Peyton Jones, S., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. In: ICFP, pp. 61 (2006)

    Google Scholar 

  9. Schrijvers, T., Peyton Jones, S., Chakravarty, M., Sulzmann, M.: Type checking with open type functions. In: ICFP, pp. 51–62 (2008)

    Google Scholar 

  10. Pierce, B.: Types and programming languages. MIT Press, Cambridge (2002)

    MATH  Google Scholar 

  11. Devriese, D., Piessens, F.: Explicitly recursive grammar combinators - Implemention of some grammar algorithms. Technical Report CW594, KULeuven CS (2010)

    Google Scholar 

  12. Moore, R.: Removing left recursion from context-free grammars. In: NAACL, pp. 249–255 (2000)

    Google Scholar 

  13. Ford, B.: Packrat parsing: simple, powerful, lazy, linear time - functional pearl. In: ICFP, pp. 36–47 (2002)

    Google Scholar 

  14. Leijen, D., Meijer, E.: Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-27, Universiteit Utrecht CS (2001)

    Google Scholar 

  15. Magalhaes, J., Holdermans, S., Jeuring, J., Löh, A.: Optimizing generics is easy! In: Workshop on Partial Evaluation and Program Manipulation, pp. 33–42 (2010)

    Google Scholar 

  16. Baars, A., Swierstra, S., Viera, M.: Typed transformations of typed abstract syntax. In: TLDI, pp. 15–26 (2009)

    Google Scholar 

  17. Baars, A., Swierstra, S.: Type-safe, self inspecting code. In: HASKELL (2004)

    Google Scholar 

  18. Viera, M., Swierstra, S., Lempsink, E.: Haskell, do you read me? constructing and composing efficient top-down parsers at runtime. In: HASKELL, pp. 63–74 (2008)

    Google Scholar 

  19. Brink, K., Holdermans, S., Löh, A.: Dependently typed grammars. In: Bolduc, C., Desharnais, J., Ktari, B. (eds.) MPC 2010. LNCS, vol. 6120, pp. 58–79. Springer, Heidelberg (2010)

    Chapter  Google Scholar 

  20. Norell, U.: Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology (2007)

    Google Scholar 

  21. Fokkinga, M., Jeuring, J., Meertens, L., Meijer, E.: A translation from attribute grammars to catamorphisms. The Squiggolist 2(1), 20–26 (1991)

    Google Scholar 

  22. Gill, A.: Type-safe observable sharing in Haskell. In: Haskell, pp. 117–128 (2009)

    Google Scholar 

  23. Claessen, K., Sands, D.: Observable sharing for functional circuit description. In: Thiagarajan, P.S., Yap, R.H.C. (eds.) ASIAN 1999. LNCS, vol. 1742, p. 62. Springer, Heidelberg (1999)

    Chapter  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

Devriese, D., Piessens, F. (2011). Explicitly Recursive Grammar Combinators. In: Rocha, R., Launchbury, J. (eds) Practical Aspects of Declarative Languages. PADL 2011. Lecture Notes in Computer Science, vol 6539. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-18378-2_9

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-18378-2_9

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-18377-5

  • Online ISBN: 978-3-642-18378-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics