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
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
Aho, A.V., Lam, M.S., Sethi, R., Ullman, J.D.: Compilers: Principles, Techniques and Tools, 2nd edn. Addison-Wesley, Reading (2006)
Johnson, S.C.: YACC. Unix Programmer’s Manual 2b (1979)
Parr, T., Quong, R.: ANTLR: A predicated-LL(k) parser generator. Software: Practice and Experience 25(7), 789–810 (1995)
Swierstra, S., Duponcheel, L.: Deterministic, error-correcting combinator parsers. In: Advanced Functional Programming, pp. 184–207 (1996)
Sabry, A.: What is a purely functional language? JFP 8(1), 1–22 (1998)
Sheard, T., Peyton Jones, S.: Template meta-programming for Haskell. SIGPLAN Notices 37(12), 75 (2002)
Yakushev, A., Holdermans, S., Löh, A., Jeuring, J.: Generic programming with fixed points for mutually recursive datatypes. In: ICFP, pp. 233–244 (2009)
Peyton Jones, S., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. In: ICFP, pp. 61 (2006)
Schrijvers, T., Peyton Jones, S., Chakravarty, M., Sulzmann, M.: Type checking with open type functions. In: ICFP, pp. 51–62 (2008)
Pierce, B.: Types and programming languages. MIT Press, Cambridge (2002)
Devriese, D., Piessens, F.: Explicitly recursive grammar combinators - Implemention of some grammar algorithms. Technical Report CW594, KULeuven CS (2010)
Moore, R.: Removing left recursion from context-free grammars. In: NAACL, pp. 249–255 (2000)
Ford, B.: Packrat parsing: simple, powerful, lazy, linear time - functional pearl. In: ICFP, pp. 36–47 (2002)
Leijen, D., Meijer, E.: Parsec: Direct style monadic parser combinators for the real world. Technical Report UU-CS-2001-27, Universiteit Utrecht CS (2001)
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)
Baars, A., Swierstra, S., Viera, M.: Typed transformations of typed abstract syntax. In: TLDI, pp. 15–26 (2009)
Baars, A., Swierstra, S.: Type-safe, self inspecting code. In: HASKELL (2004)
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)
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)
Norell, U.: Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology (2007)
Fokkinga, M., Jeuring, J., Meertens, L., Meijer, E.: A translation from attribute grammars to catamorphisms. The Squiggolist 2(1), 20–26 (1991)
Gill, A.: Type-safe observable sharing in Haskell. In: Haskell, pp. 117–128 (2009)
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)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)