[antlr-interest] Can I drive "CMinusWalker.g" from an external AST?

Bob 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

serialize).

 

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);

   nodes.setTokenStream(tokens);

   CMinusWalker         walker = new CMinusWalker(nodes);

   walker.program();  

 

 



More information about the antlr-interest mailing list