ABSTRACT
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.
- A. Aho, R. Sethi, and J. Ullman. Compilers: Principles, Techniques, and Tools. Addison-Wesley, 1986]] Google ScholarDigital Library
- J. Bachrach and K. Playford. The Java syntactic extender (JSE). In Proceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications '01, pages 31--42, Tampa Bay, FL, Oct. 2001]] Google ScholarDigital Library
- J. Baker. Macros that play: Migrating from Java to Maya. Master's thesis, University of Utah, Dec. 2001. http://www.cs.utah.edu/~jbaker/maya/thesis.html]]Google Scholar
- J. Baker and W. C. Hsieh. Runtime aspect weaving through metaprogramming. In Proceedings of the First International Conference on Aspect-Oriented Software Development, Enschede, The Netherlands, Apr. 2002]] Google ScholarDigital Library
- D. Batory, B. Lofaso, and Y. Smaragdakis. JTS: Tools for implementing domain-specific languages. In Proc. of the 5th International Conference on Software Reuse, pages 143--153, Victoria, Canada, 1998]] Google ScholarDigital Library
- C. Brabrand and M. Schwartzbach. Growing languages with metamorphic syntax macros. In Proceedings of the Workshop on Partial Evaluation and Semantics-Based Program Manipulation '02, Portland, OR, Jan. 2002. http://www.brics/dk/~mis/macro.ps]] Google ScholarDigital Library
- A. Bryant, A. Catton, K. De~Volder, and G. C. Murphy. Explicit programming. In Proceedings of the First International Conference on Aspect-Oriented Software Development, Enschede, The Netherlands, Apr. 2002]] Google ScholarDigital Library
- L. Cardelli, F. Matthes, and M. Abadi. Extensible syntax with lexical scoping. Technical Report 121, DEC SRC, Feb. 1994]]Google Scholar
- C. Chambers. The Cecil Language Specification and Rationale: Version 2.0, 1995]]Google Scholar
- S. Chiba. A metaobject protocol for C++. In Proceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications'95, pages 285--299, Austin, TX, 1995]] Google ScholarDigital Library
- C. Clifton. The MultiJava project. http://www.cs.iastate.edu/~cclifton/multijava/index.shtml]]Google Scholar
- C. Clifton, G. Leavens, C. Chambers, and T. Millstein. MultiJava: Modular open classes and symmetric multiple dispatch for Java. In Proceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications '00, pages 130--146, Minneapolis, MN, Oct. 2000]] Google ScholarDigital Library
- W. Clinger and J. Reese. Macros that work. In Proceedings of the 18th Annual ACM Symposium on Principles of Programming Languages, pages 155--162, Toronto, Ontario, Jan. 1991]] Google ScholarDigital Library
- D. de Rauglaudre. Camlp4 reference manual. http://caml.inria.fr/camlp4/manual/, Jan. 2002]]Google Scholar
- W. Divoky, C. Forgione, T. Graf, C. Laborde, A. Lemonnier, and E. Wais. The Kopi project. http://www.dms.at/kopi/index.html]]Google Scholar
- R. Ducournau, M. Habib, M. Huchard, and M. Mugnier. Monotonic conflict resolution mechanisms for inheritance. In Proceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications '92, pages 16--24, Vancouver, BC, Oct. 1992]] Google ScholarDigital Library
- R. K. Dybvig, R. Hieb, and C. Bruggeman. Syntactic abstraction in Scheme. Lisp and Symbolic Computation, 5(4):pp. 295--326, 1993]] Google ScholarDigital Library
- M. Ernst, C. Kaplan, and C. Chambers. Predicate dispatching: A unified theory of dispatch. In Proceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications '98, pages 186--211, Vancouver, BC, Oct. 1998]] Google ScholarDigital Library
- E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley, Massachusetts, 1994]] Google ScholarDigital Library
- S. Ganz, A. Sabry, and W. Taha. Macros as multi-stage computations: Type-safe, generative, binding macros in MacroML. In Proceedings of the International Conference on Functional Programming '01, pages 74--85, Florence, Italy, Sept. 2001]] Google ScholarDigital Library
- R. Kelsey, W. Clinger, and J. Rees (Eds.). The revised report on the algorithmic language Scheme. ACM SIGPLAN Notices, 33(9), Sept. 1998]] Google ScholarDigital Library
- S. Krishnamurthi. Linguistic Reuse. PhD thesis, Rice University, 2001]] Google ScholarDigital Library
- D. A. Ladd and J. C. Ramming. A*: A language for implementing language processors. IEEE Transactions on Software Engineering, 21(11):894--901, Nov. 1995]] Google ScholarDigital Library
- W. Maddox. Semantically-sensitive macroprocessing. Master's thesis, University of California, Berkeley, 1989]]Google Scholar
- Microsoft. C# language specification. http://msdn.microsoft.com/library/dotnet/csspec/vclrfcsharpspec_Start.htm]]Google Scholar
- M. Poletto, W. Hsieh, D. Engler, and M. Kaashoek. "`C and tcc: A Language and Compiler for Dynamic Code Generation". ACM Transactions on Programming Languages and Systems, 21(2):324--369, 1999]] Google ScholarDigital Library
- A. Shalit. Dylan Reference Manual. Addison-Wesley, 1996]]Google Scholar
- G. Steele Jr. Common Lisp, the Language. Digital Press, second edition, 1990]] Google ScholarDigital Library
- M. Tatsubori, S. Chiba, M. Killijian, and K. Itano. OpenJava: A class-based macro system for Java. In Proceedings of the OOPSLA '00 Reflection and Software Engineering Workshop, Minneapolis, MN, Oct. 2000]] Google ScholarDigital Library
- D. Weise and R. Crew. Programmable syntax macros. In Proceedings of the SIGPLAN '93 Conference on Programming Language Design and Implementation, pages 156--165, Albuquerque, NM, June 1993]] Google ScholarDigital Library
- Xerox. The AspectJ programming guide. http://www.aspectj.org/doc/dist/progguide/]]Google Scholar
Index Terms
- Maya: multiple-dispatch syntax extension in Java
Recommendations
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 ...
Backstage Java: making a difference in metaprogramming
OOPSLA '11: Proceedings of the 2011 ACM international conference on Object oriented programming systems languages and applicationsWe propose Backstage Java (BSJ), a Java language extension which allows algorithmic, contextually-aware generation and transformation of code. BSJ explicitly and concisely represents design patterns and other encodings by employing compile-time ...
Backstage Java: making a difference in metaprogramming
OOPSLA '11We propose Backstage Java (BSJ), a Java language extension which allows algorithmic, contextually-aware generation and transformation of code. BSJ explicitly and concisely represents design patterns and other encodings by employing compile-time ...
Comments