[antlr-interest] Can I drive "CMinusWalker.g" from an external AST?
temporaryemail at comcast.net
Mon Aug 2 11:28:13 PDT 2010
Regarding "Building a tree grammar for the C-Language" chapter:
My AST for "C-" is already built by non-Antlr means, however, it does match
the "CMinus" grammar of chapter 8.2. To repeat, the AST image in 8.3, p200
exists and was constructed outside of Antlr.
I'd like to drive "CMinusWalker.g" by an in-order traversal of my AST (to
Q: Can I do this, and what is this interface going to look like?
Assume my AST nodes have token id values from "CMinus.tokens".
That is, how would this setup change?
ANTLRInputStream input = new ANTLRInputStream(System.in);
CMinusLexer lexer = new CMinusLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
CMinusParser parser = new CMinusParser(tokens);
CMinusParser.program_return r = parser.program();
CommonTree t = (CommonTree)r.getTree();
CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
CMinusWalker walker = new CMinusWalker(nodes);
More information about the antlr-interest