Maya: multiple-dispatch syntax extension in Java

We have designed and implemented Maya, a version of Java that allows programmers to extend and reinterpret its syntax. Maya generalizes macro systems by treating grammar productions as generic functions, and semantic actions on productions as multimethods on the corresponding generic functions. Programmers can write new generic functions (i.e., grammar productions) and new multimethods (i.e., semantic actions), through which they can extend the grammar of the language and change the semantics of its syntactic constructs, respectively. Maya's multimethods are compile-time metaprograms that transform abstract syntax: they execute at program compile-time, because they are semantic actions executed by the parser. Maya's multimethods can be dispatched on the syntactic structure of the input, as well as the static, source-level types of expressions in the input. In this paper we describe what Maya can do and how it works. We describe how its novel parsing techniques work and how Maya can statically detect certain kinds of errors, such as code that generates references to free variables. Finally, to demonstrate Maya's expressiveness, we describe how Maya can be used to implement the MultiJava language, which was described by Clifton et al. at OOPSLA 2000.

[1]  Gary T. Leavens,et al.  MultiJava: modular open classes and symmetric multiple dispatch for Java , 2000, OOPSLA '00.

[2]  Guy L. Steele,et al.  Common Lisp the Language , 1984 .

[3]  Jason L. Baker MACROS THAT PLAY: MIGRATING FROM JAVA TO MAYA , 2001 .

[4]  William Maddox Semantically-Sensitive Macroprocessing , 1989 .

[5]  Wilson C. Hsieh,et al.  Runtime aspect weaving through metaprogramming , 2002, AOSD '02.

[6]  Daniel Weise,et al.  Programmable syntax macros , 1993, PLDI '93.

[7]  Robert Hieb,et al.  Syntactic abstraction in scheme , 1992, LISP Symb. Comput..

[8]  Marie-Laure Mugnier,et al.  Monotonic conflict resolution mechanisms for inheritance , 1992, OOPSLA.

[9]  Craig S. Kaplan,et al.  Predicate Dispatching: A Unified Theory of Dispatch , 1998, ECOOP.

[10]  Gail C. Murphy,et al.  Explicit programming , 2002, AOSD '02.

[11]  Claus Brabrand,et al.  Growing languages with metamorphic syntax macros , 2000, PEPM '02.

[12]  Matthias Felleisen,et al.  Linguistic reuse , 2001 .

[13]  Dawson R. Engler,et al.  C and tcc: a language and compiler for dynamic code generation , 1999, TOPL.

[14]  R. Kent Dybvig,et al.  Revised5 Report on the Algorithmic Language Scheme , 1986, SIGP.

[15]  Craig Chambers The Cecil Language - Specification and Rationale - Version 3.0 , 1995 .

[16]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[17]  Harold Abelson,et al.  Revised5 report on the algorithmic language scheme , 1998, SIGP.

[18]  Yannis Smaragdakis,et al.  JTS: tools for implementing domain-specific languages , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[19]  Jonathan Rees,et al.  Macros that work , 1991, POPL '91.

[20]  Shigeru Chiba,et al.  OpenJava: A Class-Based Macro System for Java , 1999, Reflection and Software Engineering.

[21]  Shigeru Chiba,et al.  A metaobject protocol for C++ , 1995, OOPSLA.

[22]  Andrew Shalit,et al.  The Dylan Reference Manual , 1996 .

[23]  Jonathan Bachrach,et al.  The Java syntactic extender (JSE) , 2001, OOPSLA '01.

[24]  Friedrich L. Bauer,et al.  Revised report on the algorithm language ALGOL 60 , 1963, CACM.

[25]  Martín Abadi,et al.  Extensible Syntax with Lexical Scoping , 1994 .

[26]  Amr Sabry,et al.  Macros as multi-stage computations: type-safe, generative, binding macros in MacroML , 2001, ICFP '01.

[27]  Peter H. Golde,et al.  C# Language Specification , 2003 .

[28]  Marie-Laure Mugnier,et al.  Monotonic conflict resolution mechanisms for inheritance , 1992, OOPSLA 1992.

[29]  J. Christopher Ramming,et al.  A*: a language for implementing language processors , 1994, Proceedings of 1994 IEEE International Conference on Computer Languages (ICCL'94).

[30]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .