Mainstream programming languages like Java have limited support for language extensibility. Without mechanisms for syntactic abstraction, new programming styles can only be embedded in the form of libraries, limiting expressiveness. In this paper, we present Recaf, a lightweight tool for creating Java dialects; effectively extending Java with new language constructs and user defined semantics. The Recaf compiler generically transforms designated method bodies to code that is parameterized by a semantic factory (Object Algebra), defined in plain Java. The implementation of such a factory defines the desired runtime semantics. We applied our design to produce several examples from a diverse set of programming styles and two case studies: We define i) extensions for generators, asynchronous computations and asynchronous streams and ii) a Domain-Specific Language (DSL) for Parsing Expression Grammars (PEGs), in a few lines of code.

Extensible languages, Language virtualization, Object algebras, Transformation
ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences
Centrum Wiskunde & Informatica, Amsterdam, The Netherlands

Biboudis, A, Inostroza Valdera, P.A, & van der Storm, T. (2016). Recaf: Java dialects as libraries. In GPCE 2016 - Proceedings of the 2016 ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences, co-located with SPLASH 2016 (Vol. 52, pp. 2–13). doi:10.1145/2993236.2993239