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.
- 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 ScholarDigital Library
- A. Baars, S. D. Swierstra, and M. Viera. Typed transformations of typed abstract syntax. In Proceedings of TLDI 2009, pages 15--26. Google ScholarDigital Library
- A. I. Baars and S. D. Swierstra. Typing dynamic typing. In Proceedings of ICFP 2002, pages 157--166. Google ScholarDigital Library
- M. Bravenboer. Exercises in Free Syntax. Syntax Definition, Parsing, and Assimilation of Language Conglomerates. PhD thesis, Utrecht University, Utrecht, The Netherlands, January 2008.Google Scholar
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- J. Hughes. Generalising monads to arrows. Science of Computer Programming, 37(1--3):67--111, 2000. Google ScholarDigital Library
- O. Kiselyov, R. Lämmel, and K. Schupke. Strongly typed heterogeneous collections. In Proceedings of Haskell Symposium 2004, pages 96--107. Google ScholarDigital Library
- G. Mainland. Why it's nice to be quoted: quasiquoting for Haskell. In Proceedings of Haskell Symposium 2007, pages 73--82, 2007. Google ScholarDigital Library
- C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18(01):1--13, 2007. Google ScholarDigital Library
- R. Paterson. A new notation for arrows. In Proceedings of ICFP 2001, pages 229--240, 2001. Google ScholarDigital Library
- 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 ScholarDigital Library
- T. Sheard and S. P. Jones. Template meta-programming for Haskell. ACM SIGPLAN Notices, 37:60--75, December 2002. Google ScholarDigital Library
- 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 ScholarDigital Library
- M. Viera, S. D. Swierstra, and A. Dijkstra. Grammar fragments fly first-class. UU-CS 032, Utrecht University, 2011.Google Scholar
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
Index Terms
- Grammar fragments fly first-class
Recommendations
First Class Syntax, Semantics, and Their Composition
IFL '13: Proceedings of the 25th symposium on Implementation and Application of Functional LanguagesIdeally complexity is managed by composing a system out of quite a few, more or less independent, and much smaller descriptions of various aspects of the overall artefact. When describing (extensible) programming languages, attribute grammars have ...
Compositional compiler construction
We describe an implementation of an Oberon0 compiler using the techniques proposed in the CoCoCo project. The compiler is constructed out of a collection of pre-compiled, statically type-checked language-definition fragments written in Haskell. Oberon0 ...
Attribute grammars fly first-class: how to do aspect oriented programming in Haskell
ICFP '09: Proceedings of the 14th ACM SIGPLAN international conference on Functional programmingAttribute Grammars (AGs), a general-purpose formalism for describing recursive computations over data types, avoid the trade-off which arises when building software incrementally: should it be easy to add new data types and data type alternatives or to ...
Comments