skip to main content
research-article

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

Published:10 October 2010Publication History
Skip Abstract Section

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.

References

  1. }}D. Abrahams, A. Gurtovoy, C++ template metaprogramming, Concepts, Tools, and Techniques from Boost and Beyond, Addison-Wesley, Boston, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. }}A. Alexandrescu, Modern C++ Design: Generic Programming and Design Patterns Applied, Addison-Wesley, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. }}ANSI/ISO C++ Committee, Programming Languages -- C++, ISO/IEC 14882:1998(E), American National Standards Institute, 1998.Google ScholarGoogle Scholar
  4. }}K. Czarnecki, U. W. Eisenecker, R. Glück, D. Vandevoorde, T. Veldhuizen, Generative Programming and Active Libraries, Springer-Verlag, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. }}K. Czarnecki, U. W. Eisenecker, Generative Programming: Methods, Tools and Applications, Addison-Wesley, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. }}Paul Hudak, Building domain-specific embedded languages, ACM Computing Surveys (CSUR), Volume 28, Issue 4es (1996) Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}B. Karlsson, Beyond the C++ Standard Library, An Introduction to Boost, Addison-Wesley, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }}D. R. Musser, A. A. Stepanov, Algorithm-oriented Generic Libraries, Software-practice and experience 27(7), 1994, pp.623--642. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. }}B. McNamara, Y. Smaragdakis: Static interfaces in C++. In First Workshop on C++ Template Metaprogramming, October 2000Google ScholarGoogle Scholar
  14. }}B. O'Sullivan, J. Goerzen, D. Stewart, Real World Haskell, O'Reilly, 2008. ISBN: 978-0--596--51498--3 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. }}J. Siek and A. Lumsdaine: Concept checking: Binding parametric polymorphism in C++, In First Workshop on C++ Template Metaprogramming, October 2000Google ScholarGoogle Scholar
  17. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. }}B. Stroustrup, The C++ Programming Language Special Edition, Addison-Wesley, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. }}B. Stroustrup, Evolving a language in and for the real world: C++ 1991--2006. ACM HOPL-III. June 2007 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. }}Laurence Tratt, The Converge programming language, Technical report TR-05-01, Department of Computer Science, King's College London, 2005.Google ScholarGoogle Scholar
  22. }}E. Unruh, Prime number computation, ANSI X3J16--94-0075/ISO WG21--462.Google ScholarGoogle Scholar
  23. }}D. Vandevoorde, N. M. Josuttis, C++ Templates: The Complete Guide, Addison-Wesley, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. }}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 ScholarGoogle Scholar
  25. }}T. Veldhuizen, Using C++ Template Metaprograms, C++ Report vol. 7, no. 4, 1995, pp. 36--43.Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. }}T. Veldhuizen, Expression Templates, C++ Report vol. 7, no. 5, 1995, pp. 26--31.Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. }}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 ScholarGoogle Scholar
  28. }}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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. }}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 ScholarGoogle Scholar
  30. }}I. Zólyomi, Z. Porkoláb, Towards a template introspection library, LNCS Vol.3286 (2004), pp.266--282.Google ScholarGoogle ScholarCross RefCross Ref
  31. }}L. Andersson: Parsing with Haskell, October 28, 2001, http://www.cs.lth.se/eda120/assignment4/parser.pdfGoogle ScholarGoogle Scholar
  32. }}The boost lambda library. http://www.boost.org/doc/libs/1_39_0/doc/html/lambda.htmlGoogle ScholarGoogle Scholar
  33. }}The boost metaprogram libraries. http://www.boost.org/doc/libs/1_39_0/libs/mpl/docGoogle ScholarGoogle Scholar
  34. }}The boost preprocessor metaprogramming library. http://www.boost.org/doc/libs/1_41_0/libs/preprocessor/doc/index.htmlGoogle ScholarGoogle Scholar
  35. }}The boost proto library. http://www.boost.org/doc/libs/1_37_0/doc/html/proto.htmlGoogle ScholarGoogle Scholar
  36. }}The boost xpressive regular library. http://www.boost.org/doc/libs/1_38_0/doc/html/xpressive.htmlGoogle ScholarGoogle Scholar
  37. }}The Intentional Software. http://intentsoft.com/Google ScholarGoogle Scholar
  38. }}The printf grammar. http://www.cplusplus.com/reference/clibrary/cstdio/printf/Google ScholarGoogle Scholar
  39. }}The Stratego Program Transformation Language. http://strategoxt.org/Google ScholarGoogle Scholar
  40. }}Bjane Stroustrup's C++0x FAQ, http://www.research.att.com/~bs/C++0xFAQ.htmlGoogle ScholarGoogle Scholar
  41. }}Template Haskell http://www.haskell.org/haskellwiki/Template_HaskellGoogle ScholarGoogle Scholar
  42. }}Python Programming Language http://www.python.orgGoogle ScholarGoogle Scholar
  43. }}The Icon Programming Language http://www.cs.arizona.edu/iconGoogle ScholarGoogle Scholar
  44. }}Katahdin http://www.chrisseaton.com/katahdinGoogle ScholarGoogle Scholar
  45. }}The XMF programming language http://itcentre.tvu.ac.uk/~clark/xmf.htmlGoogle ScholarGoogle Scholar
  46. }}The source code of mpllibs http://github.com/sabel83/mpllibsGoogle ScholarGoogle Scholar

Index Terms

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

    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

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 46, Issue 2
      GPCE '10
      Febuary 2011
      185 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/1942788
      Issue’s Table of Contents
      • cover image ACM Conferences
        GPCE '10: Proceedings of the ninth international conference on Generative programming and component engineering
        October 2010
        198 pages
        ISBN:9781450301541
        DOI:10.1145/1868294
        • General Chair:
        • Eelco Visser,
        • Program Chair:
        • Jaakko Järvi

      Copyright © 2010 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 10 October 2010

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!