首页    期刊浏览 2024年10月06日 星期日
登录注册

文章基本信息

  • 标题:Growing Languages with Metamorphic Syntax Macros
  • 本地全文:下载
  • 作者:Claus Brabrand ; Michael I. Schwartzbach
  • 期刊名称:BRICS Report Series
  • 印刷版ISSN:0909-0878
  • 出版年度:2000
  • 卷号:7
  • 期号:24
  • 出版社:Aarhus University
  • 摘要:"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.
国家哲学社会科学文献中心版权所有