I am using the ANTLR parser generator for my project. I need to define multiple TreeParser implementations to operate on my AST. The documentation says you can do this, but it doesn't say how. I tried all the obvious things but couldn't make it work.
1) if you put the treeparsers in the same grammar file, it complains and says, you are not allowed to define more than one TreeParser per grammar file. (No idea why this restriction exists!)
2) If you put the second TreeParser in its own grammar file, then it generates its own TokenTypes interface and generates a new numbering for all the tokens, that is not compatible with the numbering used in my AST. When you parse the AST using this second TreeParser, it misinterprets all of the tokens.
I need the second TreeParser to share the same input token list from the ones defined in the first grammar file. How to do this??
I have looked through the ANTLR manual and I am surprised that it doesn't explain how to do this, since the ability to code more than one class is a pretty standard feature of most
Java tools(!)..
Thanks,
Geoffrey