skip to main content
10.1145/2427048.2427053acmotherconferencesArticle/Chapter ViewAbstractPublication PagesldtaConference Proceedingsconference-collections
research-article

Grammar fragments fly first-class

Published:31 March 2012Publication History

ABSTRACT

We present a Embedded Domain Specific language in the form of a Haskell library (EDSL) for expressing grammar (fragments), using typed abstract syntax with observable references. Thus grammar fragments have become fully typed, first-class Haskell values.

We can analyze and transform such representations and generate parsers from them. What makes our approach special is that we can combine embedded grammar fragments on the fly, i.e. after they have been compiled and that the Haskell type system is used to check the consistency of a collection of combined fragments.

We show how we can extend an initial, limited grammar embedded in a compiler with new syntactic constructs, either by introducing new non-terminals or by adding new productions for existing non-terminals. We do not impose any restrictions on the individual grammar fragments, nor on the structure as a whole.

References

  1. A. Baars, S. Doaitse Swierstra, and M. Viera. Typed transformations of typed grammars: The left corner transform. Electronic Notes in Theoretical Computer Science, 253:51--64, September 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. Baars, S. D. Swierstra, and M. Viera. Typed transformations of typed abstract syntax. In Proceedings of TLDI 2009, pages 15--26. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. A. I. Baars and S. D. Swierstra. Typing dynamic typing. In Proceedings of ICFP 2002, pages 157--166. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. M. Bravenboer. Exercises in Free Syntax. Syntax Definition, Parsing, and Assimilation of Language Conglomerates. PhD thesis, Utrecht University, Utrecht, The Netherlands, January 2008.Google ScholarGoogle Scholar
  5. K. Brink, S. Holdermans, and A. Löh. Dependently typed grammars. In Mathematics of Program Construction, volume 6120 of Lecture Notes in Computer Science, pages 58--79. 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. D. Devriese and F. Piessens. Explicitly recursive grammar combinators: a better model for shallow parser DSLs. In Proceedings of PADL 2011, pages 84--98. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. J. Hughes. Generalising monads to arrows. Science of Computer Programming, 37(1--3):67--111, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. O. Kiselyov, R. Lämmel, and K. Schupke. Strongly typed heterogeneous collections. In Proceedings of Haskell Symposium 2004, pages 96--107. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. G. Mainland. Why it's nice to be quoted: quasiquoting for Haskell. In Proceedings of Haskell Symposium 2007, pages 73--82, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18(01):1--13, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. R. Paterson. A new notation for arrows. In Proceedings of ICFP 2001, pages 229--240, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. S. Peyton Jones, D. Vytiniotis, S. Weirich, and G. Washburn. Simple unification-based type inference for gadts. SIGPLAN Not., 41(9):50--61, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. T. Sheard and S. P. Jones. Template meta-programming for Haskell. ACM SIGPLAN Notices, 37:60--75, December 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. S. D. Swierstra. Combinator parsers: a short tutorial. In A. Bove, L. Barbosa, A. Pardo, and J. Sousa Pinto, editors, Language Engineering and Rigorous Software Development, volume 5520 of LNCS, pages 252--300. Spinger, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. M. Viera, S. D. Swierstra, and A. Dijkstra. Grammar fragments fly first-class. UU-CS 032, Utrecht University, 2011.Google ScholarGoogle Scholar
  16. M. Viera, S. D. Swierstra, and E. Lempsink. Haskell, do you read me?: constructing and composing efficient top-down parsers at runtime. In Proceedings of Haskell Symposium 2008, pages 63--74. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. M. Viera, S. D. Swierstra, and W. Swierstra. Attribute grammars fly first-class: how to do aspect oriented programming in haskell. In Proceedings of ICFP 2009, pages 245--256. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. A. R. Yakushev, S. Holdermans, A. Löh, and J. Jeuring. Generic programming with fixed points for mutually recursive datatypes. In Proceedings of ICFP 2009, pages 233--244, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Grammar fragments fly first-class

      Recommendations

      Comments

      Login options

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

      Sign in
      • Published in

        cover image ACM Other conferences
        LDTA '12: Proceedings of the Twelfth Workshop on Language Descriptions, Tools, and Applications
        March 2012
        77 pages
        ISBN:9781450315364
        DOI:10.1145/2427048

        Copyright © 2012 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 31 March 2012

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader