Advertisement

Creating Domain-Specific Languages by Composing Syntactical Constructs

  • Viktor PalmkvistEmail author
  • David Broman
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11372)

Abstract

Creating a programming language is a considerable undertaking, even for relatively small domain-specific languages (DSLs). Most approaches to ease this task either limit the flexibility of the DSL or consider entire languages as the unit of composition. This paper presents a new approach using syntactical constructs (also called syncons) for defining DSLs in much smaller units of composition while retaining flexibility. A syntactical construct defines a single language feature, such as an if statement or an anonymous function. Each syntactical construct is fully self-contained: it specifies its own concrete syntax, binding semantics, and runtime semantics, independently of the rest of the language. The runtime semantics are specified as a translation to a user defined target language, while the binding semantics allow name resolution before expansion. Additionally, we present a novel approach for dealing with syntactical ambiguity that arises when combining languages, even if the languages are individually unambiguous. The work is implemented and evaluated in a case study, where small subsets of OCaml and Lua have been defined and composed using syntactical constructs.

Notes

Acknowledgements

The authors would like to thank Elias Castegren, Mads Dam, Philipp Haller, Daniel Lundén, Saranya Natarajan, Oscar Eriksson, and Rodothea Myrsini Tsoupidi for valuable input and feedback. This project is financially supported by the Swedish Foundation for Strategic Research (FFL15-0032).

References

  1. 1.
    Augustsson, L., Mansell, H., Sittampalam, G.: Paradise: a two-stage dsl embedded in haskell. In: Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, ICFP 2008, pp. 225–228. ACM (2008)Google Scholar
  2. 2.
    Bjesse, P., Claessen, K., Sheeran, M., Singh, S.: Lava: hardware design in Haskell. In: Proceedings of the Third ACM SIGPLAN International Conference on Functional Programming, pp. 174–184. ACM Press, New York (1998)CrossRefGoogle Scholar
  3. 3.
    Bravenboer, M., Kalleberg, K.T., Vermaas, R., Visser, E.: Stratego/XT 0.17. A language and toolset for program transformation. Sci. Comput. Program. 72(1), 52–70 (2008)MathSciNetCrossRefGoogle Scholar
  4. 4.
    Broman, D., Siek, J.G.: Gradually typed symbolic expressions. In: Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2018, pp. 15–29. ACM, New York (2018)Google Scholar
  5. 5.
    Cantor, D.G.: On the ambiguity problem of backus systems. J. ACM 9(4), 477–479 (1962)MathSciNetCrossRefGoogle Scholar
  6. 6.
    Dybvig, R.K., Hieb, R., Bruggeman, C.: Syntactic abstraction in scheme. LISP Symb. Comput. 5(4), 295–326 (1993)CrossRefGoogle Scholar
  7. 7.
    Earley, J.: An efficient context-free parsing algorithm. Commun. ACM 13(2), 94–102 (1970)CrossRefGoogle Scholar
  8. 8.
    Ekman, T., Hedin, G.: The JastAdd system – modular extensible compiler construction. Sci. Comput. Program. 69(1), 14–26 (2007)MathSciNetCrossRefGoogle Scholar
  9. 9.
    Flatt, M.: Binding as sets of scopes. In: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, pp. 705–717. ACM, New York (2016)Google Scholar
  10. 10.
    Flatt, M., PLT: Reference: Racket. Technical report PLT-TR-2010-1, PLT Design Inc. (2010)Google Scholar
  11. 11.
    Giorgidze, G., Nilsson, H.: Embedding a functional hybrid modelling language in haskell. In: Scholz, S.-B., Chitil, O. (eds.) IFL 2008. LNCS, vol. 5836, pp. 138–155. Springer, Heidelberg (2011).  https://doi.org/10.1007/978-3-642-24452-0_8CrossRefGoogle Scholar
  12. 12.
    Heering, J., Hendriks, P.R.H., Klint, P., Rekers, J.: The syntax definition formalism SDF–reference manual–. ACM SIGPLAN Not. 24(11), 43–75 (1989)CrossRefGoogle Scholar
  13. 13.
    Herman, D., Wand, M.: A theory of hygienic macros. In: Drossopoulou, S. (ed.) ESOP 2008. LNCS, vol. 4960, pp. 48–62. Springer, Heidelberg (2008).  https://doi.org/10.1007/978-3-540-78739-6_4CrossRefGoogle Scholar
  14. 14.
    Hudak, P.: Building domain-specific embedded languages. ACM Comput. Surv. 28, 196 (1996)CrossRefGoogle Scholar
  15. 15.
    Kaminski, T., Kramer, L., Carlson, T., Van Wyk, E.: Reliable and automatic composition of language extensions to C: the ableC extensible language framework. Proc. ACM Program. Lang. 1(OOPSLA), 98:1–98:29 (2017)CrossRefGoogle Scholar
  16. 16.
    Lorenzen, F., Erdweg, S.: Sound type-dependent syntactic language extension. In: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), vol. 51, pp. 204–216. ACM Press (2016)Google Scholar
  17. 17.
    Omar, C., Kurilova, D., Nistor, L., Chung, B., Potanin, A., Aldrich, J.: Safely composable type-specific languages. In: Jones, R. (ed.) ECOOP 2014. LNCS, vol. 8586, pp. 105–130. Springer, Heidelberg (2014).  https://doi.org/10.1007/978-3-662-44202-9_5CrossRefGoogle Scholar
  18. 18.
    Palmkvist, V.: Building Programming Languages, Construction by Construction. Master’s thesis, KTH Royal Institute of Technology (2018)Google Scholar
  19. 19.
    Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. In: Proceedings of the Ninth International Conference on Generative Programming and Component Engineering, GPCE 2010, pp. 127–136. ACM, New York (2010)Google Scholar
  20. 20.
    Sheard, T., Jones, S.P.: Template meta-programming for Haskell. In: Haskell 2002: Proceedings of the 2002 ACM SIGPLAN Workshop on Haskell, pp. 1–16. ACM Press, New York (2002)Google Scholar
  21. 21.
    Silkensen, E., Siek, J.: Well-typed islands parse faster. In: Loidl, H.-W., Peña, R. (eds.) TFP 2012. LNCS, vol. 7829, pp. 69–84. Springer, Heidelberg (2013).  https://doi.org/10.1007/978-3-642-40447-4_5CrossRefGoogle Scholar
  22. 22.
    Stansifer, P., Wand, M.: Romeo. In: Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming - ICFP 2014, vol. 49, pp. 53–65. ACM Press, New York (2014)Google Scholar
  23. 23.
    Steele, Jr., G.L.: An overview of COMMON LISP. In: Proceedings of the 1982 ACM Symposium on LISP and Functional Programming, LFP 1982, pp. 98–107. ACM, New York (1982)Google Scholar
  24. 24.
    Sujeeth, A.K., et al.: Delite: a compiler architecture for performance-oriented embedded domain-specific languages. ACM Trans. Embed. Comput. Syst. (TECS) 13(4s), 134:1–134:25 (2014)Google Scholar
  25. 25.
    Van Wyk, E., Bodin, D., Gao, J., Krishnan, L.: Silver: an extensible attribute grammar system. Sci. Comput. Program. 75(1–2), 39–54 (2010)MathSciNetzbMATHGoogle Scholar
  26. 26.
    Van Wyk, E.R., Schwerdfeger, A.C.: Context-aware scanning for parsing extensible languages. In: Proceedings of the 6th International Conference on Generative Programming and Component Engineering - GPCE 2007, p. 63. ACM Press, New York (2007)Google Scholar
  27. 27.
    Wan, Z., Hudak, P.: Functional reactive programming from first principles. In: PLDI 2000: Proceedings of the ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation, pp. 242–252. ACM Press, New York (2000)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2019

Authors and Affiliations

  1. 1.KTH Royal Institute of TechnologyStockholmSweden

Personalised recommendations