What are AST Macros?

Jonathan M Davis jmdavisprog at gmail.com
Thu Jul 8 17:43:39 PDT 2010


Periodically, the term AST macros come up in the discussions here as a possible 
addition to the language - they even get discussed briefly in TDPL as a possible 
replacement for template mxins. However, I don't think that I've ever seen an 
actual explanation for what exactly is meant by the term AST macro. This raises 
two questions

1. What are AST macros and how do they differ from C-style macros? We obviously 
aren't going to be adding macros like that to D, since that would be dangerous. 
But what would a macro be then if it's not a textual replacement? The best I can 
think of would be that you'd have to indicate the macros to be replaced by 
surrounding them with macro() or something rather than letting any and all text 
that matches  be replaced. So, I really don't know what AST macros are supposed 
to be other than they're macros of some kind and better than C-style macros.

2. What does AST stand for? The best that I can come up with for what it could 
stand for would be Abstract Syntax Tree, which is a nice, Computer Sciency, 
compiler-related term, but I haven't a clue how that would relate to macros. So, 
maybe an answer to the first question would answer this one as well, but an 
explanation would be nice.

- Jonathan M Davis


More information about the Digitalmars-d mailing list