JastAdd + ANTLR 3 Advice?
Up to JastAdd
Does anyone have experience/advice in using JastAdd in combination with ANTLR 3?
I'm experimenting with both JastAdd and ANTLR 3, so that I can be well-armed for future compiler-related projects
. Not surprisingly, each tool is sort of attached to its own AST node hierarchy. After some thinking and experimenting, I decided that the best way for me to connect ANTLR and JastAdd was the following:
- Write an ANTLR grammar that does the parsing of text, producing a tree of ANTLR nodes.
- Write an ANTLR tree grammar that translates the ANTLR AST into the "equivalent" JastAdd AST.
- Let JastAdd do its thing, conputing attributes, etc.
The advantage of this approach is that I can use each tool for it is best at (steps 1 and 3), without worrying too much about connecting it to the other tool. The connection between the tools is contained in step 2. The main disadvantage of course is the need for step 2 at all. However, I found it somewhat inconvenient to build the JastAdd AST directly from the ANTLR grammar, and doing so "pollutes" the basic grammar with semantic actions that couple the grammar to JastAdd. It seemed better to encapsulate the translation to JastAdd in a separate step.
Thanks for any advice! ---
Eric.