ABSTRACT
Lisp has shown that a programmable syntax macro system acts as an adjunct to the compiler that gives the programmer important and powerful abstraction facilities not provided by the language. Unlike simple token substitution macros, such as are provided by CPP (the C preprocessor), syntax macros operate on Abstract Syntax Trees (ASTs). Programmable syntax macro systems have not yet been developed for syntactically rich languages such as C because rich concrete syntax requires the manual construction of syntactically valid program fragments, which is a tedious, difficult, and error prone process. Also, using two languages, one for writing the program, and one for writing macros, is another source of complexity. This research solves these problems by having the macro language be a minimal extension of the programming language, by introducing explicit code template operators into the macro language, and by using a type system to guarantee, at macro definition time, that all macros and macro functions only produce syntactically valid program fragments. The code template operators make the language context sensitive, which requires changes to the parser. The parser must perform type analysis in order to parse macro definitions, or to parse user code that invokes macros.
- 1.ANSi Standard on C, X3.159.1989, ANSI, NY, 1990.Google Scholar
- 2.Cameron, R. D., "Software reuse with metaprogramming systems," Proceedings of the Fifth Annual Pacific Northwest Software Quality Conference, OR, pp. 223- 32, 1987Google Scholar
- 3.Campbell, W. R., "A compiler definition facility based on the Syntactic Macro," Computer Journal 21(1), pp. 35-41, 1975Google ScholarCross Ref
- 4.Cheatham, T. E., "The introduction of definitional facilities into higher level programming languages," pp. 623-637, Proc. AFIPS (Fall Joint Computer Conference, 29), 1966Google Scholar
- 5.Harbison, S., and Steele, G., C, ARe. ference Manual, Third Edition, Prentice Hall, 1991 Google ScholarDigital Library
- 6.Hieb, R., Dybvig, R. K., Bruggeman, C., "Syntactic abstraction in Scheme," University of Indiana Computer Science Technical Report 355, 18 pages, June 1992 (Revised July 1992).Google Scholar
- 7.Jonker, Todd, Personal Communication, 1992Google Scholar
- 8.Kohlbecker, Eugene, Friedman, Daniel P., FeHeisen, Matthias, Duba, Bruce, "Hygienic macro expansion," Proceedings of the 1986 ACM Conference on Lisp and Functional Programming, pp. 151-161, ACM Press, NY, 1986 Google ScholarDigital Library
- 9.Leavenworth, B. M., "Syntax Macros and Extended Translation," CACM 9(11), pp. 790-793, 1966 Google ScholarDigital Library
- 10.Maddox, William, Semantically-Sensit2ve Macroprocessing Report No. UCB/CSD 89/545, (Master's Thesis), 82 pages, University of California, Berkeley, 1989. Google ScholarDigital Library
- 11.Samples, Dain, M5, Electronic Announcement oll comp.compilers newsgroup, 1992Google Scholar
- 12.Steele, G., Common Lisp, The Language, Digital Press, 1984. Google ScholarDigital Library
- 13.Strachey, C., "A general purpose macrogenerator," Computer Journal, 8(3), pp. 225-241, 1965Google ScholarCross Ref
- 14.Vidart, J., Extensions syntaxiques dans une contexte LL(1), University of Grenoble, Th'ese pour obtenir le grade de Docteur de troisi'eme cycle, 1974Google Scholar
- 15.Bliss-11 Programmer's Manual, CMU Department of Computer Science, 1974.Google Scholar
Index Terms
Programmable syntax macros
Recommendations
Macros for domain-specific languages
Macros provide a powerful means of extending languages. They have proven useful in both general-purpose and domain-specific programming contexts. This paper presents an architecture for implementing macro-extensible DSLs on top of macro-extensible host ...
Composable and compilable macros:: you want it when?
Many macro systems, especially for Lisp and Scheme, allow macro transformers to perform general computation. Moreover, the language for implementing compile-time macro transformers is usually the same as the language for implementing run-time functions. ...
Syntax macros and extended translation
A translation approach is described which allows one to extend the syntax and semantics of a given high-level base language by the use of a new formalism called a syntax-macro. Syntax-macros define string transformations based on syntactic elements of ...
Comments