Growing Languages with Metamorphic Syntax Macros

Authors

  • Claus Brabrand
  • Michael I. Schwartzbach

DOI:

https://doi.org/10.7146/brics.v7i24.20151

Abstract

"From now on, a main goal in designing a language should be to plan for growth."
Guy Steele: Growing a Language, OOPSLA'98 invited talk.
We present our experiences with a syntax macro language augmented with a concept of metamorphisms. We claim this forms a general abstraction mechanism for
growing (domain-specific) extensions of programming languages.
Our syntax macros are similar to previous work in that the compiler accepts collections of grammatical rules that extend the syntax in which a subsequent program may be written. We exhibit how almost arbitrary extensions can be defined in a purely declarative manner without resorting to compile-time programming. The macros are
thus terminating in that parsing is guaranteed to terminate, hygienic since full-conversion eliminates the risk of name clashes, and transparent such that subsequent phases in the compiler are unaware of them. Error messages from later phases in the compiler are tracked through all macro invocations to pinpoint their sources in the extended syntax. A concept of metamorphic rules allows the arguments of a macro to be defined
in an almost arbitrary meta level grammar and then to be morphed into the host language. We show through examples how creative use of metamorphic syntax macros may be used not only to create convenient shorthand notation but also to introduce new
language concepts and mechanisms. In fact, whole new languages can be created at surprisingly low cost. The resulting programs are significantly easier to understand and maintain.
This work is fully implemented as part of the system for defining
interactive Web services, but could find use in many other languages.

Downloads

Published

2000-01-24

How to Cite

Brabrand, C., & Schwartzbach, M. I. (2000). Growing Languages with Metamorphic Syntax Macros. BRICS Report Series, 7(24). https://doi.org/10.7146/brics.v7i24.20151