Domain-specific language integration with compile-time parser generator library

Smooth integration of domain-specific languages into a general purpose host language requires absorbing of domain code written in arbitrary syntax. The integration should cause minimal syntactical and semantic overhead and introduce minimal dependency on external tools. In this paper we discuss a DSL integration technique for the C++ programming language. The solution is based on compile-time parsing of the DSL code. The parser generator is a C++ template metaprogram reimplementation of a runtime Haskell parser generator library. The full parsing phase is executed when the host program is compiled. The library uses only standard C++ language features, thus our solution is highly portable. As a demonstration of the power of this approach, we present a highly efficient and type-safe version of printf and the way it can be constructed using our library. Despite the well known syntactical difficulties of C++ template metaprograms, building embedded languages using our library leads to self-documenting C++ source code.

[1]  Bjarne Stroustrup,et al.  Concepts: linguistic support for generic programming in C++ , 2006, OOPSLA '06.

[2]  Björn Karlsson,et al.  Beyond the C++ Standard Library: An Introduction to Boost , 2005 .

[3]  Douglas Gregor,et al.  C++ Templates: The Complete Guide , 2002 .

[4]  Charles Simonyi,et al.  Intentional software , 2006, OOPSLA '06.

[5]  Keren Lenz,et al.  Simple and safe SQL queries with c++ templates , 2007, GPCE '07.

[6]  Yannis Smaragdakis,et al.  Static interfaces in C , 2000 .

[7]  Jeremy G. Siek,et al.  Concept Checking: Binding Parametric Polymorphism in C++ , 2000 .

[8]  Zoltán Porkoláb,et al.  Towards a General Template Introspection Library , 2004, GPCE.

[9]  Todd L. Veldhuizen,et al.  Expression templates , 1996 .

[10]  Bjarne Stroustrup,et al.  Specifying C++ concepts , 2006, POPL '06.

[11]  Sibylle Schupp,et al.  Multi-Language Library Development. From Haskell Type Classes to C++ Concepts. , 2007 .

[12]  Henrietta Hardy Mrs Hammond The complete guide , 1883 .

[13]  David Abrahams,et al.  C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond (C++ In-Depth Series) , 2004 .

[14]  Paul Hudak,et al.  Building domain-specific embedded languages , 1996, CSUR.

[15]  Krzysztof Czarnecki,et al.  Generative programming - methods, tools and applications , 2000 .

[16]  Laurence Tratt,et al.  The Converge programming language. , 2005 .

[17]  Bjarne Stroustrup,et al.  Evolving a language in and for the real world: C++ 1991-2006 , 2007, HOPL.

[18]  Jeremy G. Siek,et al.  Essential language support for generic programming , 2005, PLDI '05.

[19]  Robert Glück,et al.  Generative Programming and Active Libraries , 1998, Generic Programming.

[20]  Bjarne Stroustrup,et al.  The C++ Programming Language: Special Edition , 2000 .

[21]  Björn Karlsson,et al.  Beyond the C++ Standard Library , 2005 .

[22]  Zoltán Porkoláb,et al.  Debugging C++ template metaprograms , 2006, GPCE '06.

[23]  Robert Glück,et al.  Generative Programming and Active Libraries , 1998, Generic Programming.

[24]  Douglas C. Schmidt,et al.  Generative Programming and Component Engineering, 5th International Conference, GPCE 2006, Portland, Oregon, USA, October 22-26, 2006, Proceedings , 2006, GPCE.

[25]  Dennis Gannon,et al.  Active Libraries: Rethinking the roles of compilers and libraries , 1998, ArXiv.

[26]  Todd L. Veldhuizen,et al.  Using C++ template metaprograms , 1996 .

[27]  Eelco Visser,et al.  Program Transformation with Stratego/XT: Rules, Strategies, Tools, and Systems in Stratego/XT 0.9 , 2003, Domain-Specific Program Generation.

[28]  Alexander A. Stepanov,et al.  Algorithm‐oriented generic libraries , 1994, Softw. Pract. Exp..

[29]  Andrei Alexandrescu,et al.  Modern C++ design: generic programming and design patterns applied , 2001 .

[30]  Eric Van Wyk,et al.  Context-aware scanning for parsing extensible languages , 2007, GPCE '07.

[31]  Jaakko Järvi,et al.  Variadic templates for C++ , 2007, SAC '07.

[32]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[33]  F. Alan Andersen,et al.  The American National Standards Institute , 1984, IEEE Engineering in Medicine and Biology Magazine.

[34]  David Abrahams,et al.  C++ template metaprogramming , 2005 .