[antlr-interest] best approach for macro substitution

Gabriel Erzse gabriel_erzse at yahoo.com
Wed Sep 2 07:05:06 PDT 2009


Hi,

What do you think would be the best approach to solve macro substitution with ANTLR?

One option I've seen is to build it in the lexer. I've seen a sample grammar for a C preprocessor on the website, but I didn't go in detail into it. My language is not C, but a custom language that resembles more to Java.

Another option I'm thinking of is to do the macro replacement after the AST is built? Basically walk over the tree, detect macro patterns in the subtrees and do needed replacements. But this one sounds messy, with all the involved node manipulations.

Another one would be to integrate some external framework. For example there is the GNU M4 framework. Don't know if there is something similar that can be easily plugged into ANTLR.

If someone has experience with macro handling, I could use any suggestion.

Thanks,
Gabi.



More information about the antlr-interest mailing list