Abstract
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.
- }}D. Abrahams, A. Gurtovoy, C++ template metaprogramming, Concepts, Tools, and Techniques from Boost and Beyond, Addison-Wesley, Boston, 2004. Google Scholar
Digital Library
- }}A. Alexandrescu, Modern C++ Design: Generic Programming and Design Patterns Applied, Addison-Wesley, 2001. Google Scholar
Digital Library
- }}ANSI/ISO C++ Committee, Programming Languages -- C++, ISO/IEC 14882:1998(E), American National Standards Institute, 1998.Google Scholar
- }}K. Czarnecki, U. W. Eisenecker, R. Glück, D. Vandevoorde, T. Veldhuizen, Generative Programming and Active Libraries, Springer-Verlag, 2000. Google Scholar
Digital Library
- }}K. Czarnecki, U. W. Eisenecker, Generative Programming: Methods, Tools and Applications, Addison-Wesley, 2000. Google Scholar
Digital Library
- }}G. Dos Reis, B. Stroustrup, Specifying C++ concepts, Proceedings of the 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), 2006, pp. 295--308. Google Scholar
Digital Library
- }}Paul Hudak, Building domain-specific embedded languages, ACM Computing Surveys (CSUR), Volume 28, Issue 4es (1996) Google Scholar
Digital Library
- }}Y. Gil, K. Lenz, Simple and Safe SQL queries with C++ templates, In: Charles Consela and Julia L. Lawall (eds), Generative Programming and Component Engineering, 6th International Conference, GPCE 2007, Salzburg, Austria, October 1--3, 2007, pp.13--24. Google Scholar
Digital Library
- }}Douglas Gregor, Jaakko Jarvi, Variadic templates for C++, Symposium on Applied Computing, Proceedings of the 2007 ACM symposium on Applied computing, Seoul, Korea (2007), pp.1101--1108. Google Scholar
Digital Library
- }}D. Gregor, J. Jarvi, J.G. Siek, G. Dos Reis, B. Stroustrup, A. Lumsdaine, Concepts: Linguistic Support for Generic Programming in C++, In Proceedings of the 2006 ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA'06), October 2006. Google Scholar
Digital Library
- }}B. Karlsson, Beyond the C++ Standard Library, An Introduction to Boost, Addison-Wesley, 2005. Google Scholar
Digital Library
- }}D. R. Musser, A. A. Stepanov, Algorithm-oriented Generic Libraries, Software-practice and experience 27(7), 1994, pp.623--642. Google Scholar
Digital Library
- }}B. McNamara, Y. Smaragdakis: Static interfaces in C++. In First Workshop on C++ Template Metaprogramming, October 2000Google Scholar
- }}B. O'Sullivan, J. Goerzen, D. Stewart, Real World Haskell, O'Reilly, 2008. ISBN: 978-0--596--51498--3 Google Scholar
Digital Library
- }}Z. Porkoláb, J. Mihalicza, Á. Sipos, Debugging C++ template metaprograms, In: Stan Jarzabek, Douglas C. Schmidt, Todd L. Veldhuizen (Eds.): Generative Programming and Component Engineering, 5th International Conference, GPCE 2006, Portland, Oregon, USA, October 22--26, 2006, Proceedings. ACM 2006 ISBN 1--59593--237--2, pp. 255--264. Google Scholar
Digital Library
- }}J. Siek and A. Lumsdaine: Concept checking: Binding parametric polymorphism in C++, In First Workshop on C++ Template Metaprogramming, October 2000Google Scholar
- }}J. Siek, A. Lumsdaine, Essential Language Support for Generic Programming, Proceedings of the ACM SIGPLAN 2005 conference on Programming language design and implementation, New York, USA, pp 73--84. Google Scholar
Digital Library
- }}C. Simonyi, M. Christerson, S. Clifford, Intentional software, In Proceedings of the 21st annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications, October 22--26, 2006, Portland, Oregon, USA, pp. 451--465. Google Scholar
Digital Library
- }}B. Stroustrup, The C++ Programming Language Special Edition, Addison-Wesley, 2000. Google Scholar
Digital Library
- }}B. Stroustrup, Evolving a language in and for the real world: C++ 1991--2006. ACM HOPL-III. June 2007 Google Scholar
Digital Library
- }}Laurence Tratt, The Converge programming language, Technical report TR-05-01, Department of Computer Science, King's College London, 2005.Google Scholar
- }}E. Unruh, Prime number computation, ANSI X3J16--94-0075/ISO WG21--462.Google Scholar
- }}D. Vandevoorde, N. M. Josuttis, C++ Templates: The Complete Guide, Addison-Wesley, 2003. Google Scholar
Digital Library
- }}T. Veldhuizen, D. Gannon, Active libraries: Rethinking the roles of compilers and libraries. In Proceedings of the SIAM Workshop on Object Oriented Methods for Inter-operable Scientic and Engineering Computing (OO'98). SIAM Press, 1998 pp. 21--23Google Scholar
- }}T. Veldhuizen, Using C++ Template Metaprograms, C++ Report vol. 7, no. 4, 1995, pp. 36--43.Google Scholar
Digital Library
- }}T. Veldhuizen, Expression Templates, C++ Report vol. 7, no. 5, 1995, pp. 26--31.Google Scholar
Digital Library
- }}E. Visser, Program Transformation with Stratego/XT: Rules, Strategies, Tools, and Systems in StrategoXT-0.9. In C. Lengauer et al., editors, Domain-Specific Program Generation, vol. 3016 of Lecture Notes in Computer Science, pp. 216--238. Spinger-Verlag, June 2004.Google Scholar
- }}E.R. Van Wyk, A.C. Schwerdfeger, Context-aware scanning for parsing extensible languages, Proceedings of the 6th international conference on Generative programming and component engineering, October 01-03, 2007, Salzburg, Austria, pp. 63--72. Google Scholar
Digital Library
- }}M. Zalewski, A. P. Priesnitz, C. Ionescu, N. Botta, and S. Schupp, Multi-language library development: From Haskell type classes to C++ concepts, In MPOOL 2007 Ecoop workshp, 2007.Google Scholar
- }}I. Zólyomi, Z. Porkoláb, Towards a template introspection library, LNCS Vol.3286 (2004), pp.266--282.Google Scholar
Cross Ref
- }}L. Andersson: Parsing with Haskell, October 28, 2001, http://www.cs.lth.se/eda120/assignment4/parser.pdfGoogle Scholar
- }}The boost lambda library. http://www.boost.org/doc/libs/1_39_0/doc/html/lambda.htmlGoogle Scholar
- }}The boost metaprogram libraries. http://www.boost.org/doc/libs/1_39_0/libs/mpl/docGoogle Scholar
- }}The boost preprocessor metaprogramming library. http://www.boost.org/doc/libs/1_41_0/libs/preprocessor/doc/index.htmlGoogle Scholar
- }}The boost proto library. http://www.boost.org/doc/libs/1_37_0/doc/html/proto.htmlGoogle Scholar
- }}The boost xpressive regular library. http://www.boost.org/doc/libs/1_38_0/doc/html/xpressive.htmlGoogle Scholar
- }}The Intentional Software. http://intentsoft.com/Google Scholar
- }}The printf grammar. http://www.cplusplus.com/reference/clibrary/cstdio/printf/Google Scholar
- }}The Stratego Program Transformation Language. http://strategoxt.org/Google Scholar
- }}Bjane Stroustrup's C++0x FAQ, http://www.research.att.com/~bs/C++0xFAQ.htmlGoogle Scholar
- }}Template Haskell http://www.haskell.org/haskellwiki/Template_HaskellGoogle Scholar
- }}Python Programming Language http://www.python.orgGoogle Scholar
- }}The Icon Programming Language http://www.cs.arizona.edu/iconGoogle Scholar
- }}Katahdin http://www.chrisseaton.com/katahdinGoogle Scholar
- }}The XMF programming language http://itcentre.tvu.ac.uk/~clark/xmf.htmlGoogle Scholar
- }}The source code of mpllibs http://github.com/sabel83/mpllibsGoogle Scholar
Index Terms
Domain-specific language integration with compile-time parser generator library
Recommendations
Domain specific language implementation via compile-time meta-programming
Domain specific languages (DSLs) are mini-languages that are increasingly seen as being a valuable tool for software developers and non-developers alike. DSLs must currently be created in an ad-hoc fashion, often leading to high development costs and ...
Domain-specific language integration with compile-time parser generator library
GPCE '10: Proceedings of the ninth international conference on Generative programming and component engineeringSmooth 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 ...
Layout-sensitive language extensibility with SugarHaskell
Haskell '12: Proceedings of the 2012 Haskell SymposiumProgrammers need convenient syntax to write elegant and concise programs. Consequently, the Haskell standard provides syntactic sugar for some scenarios (e.g., do notation for monadic code), authors of Haskell compilers provide syntactic sugar for more ...







Comments