[antlr-interest] Resetting an AST tree walker
Steve Souza
steve at stevesouza.com
Mon Apr 20 09:13:42 PDT 2009
I have an AST TreeWalker that inherits from TreeParser. In the code below
this class is called MyASTWalker. The language I am creating takes a
string like the following: 7*5+myvariable
myvariable is determined at runtime. The first call to calc() works (this
calculates the answer), however subseqent calls cause an EOF error. I could
recreate MyASTWalker(nodes) for each call to calc(), however that seems
inefficient. Is there a way to accomplish the same thing by calling reset()
on a particular object such as TreeParser or CommonTreeNodeStream?
Also, what is the difference between CommonTreeNodeStream and
BufferedTreeNodeStream?
...
CommonTree commonTree=(CommonTree)ast.getTree();
CommonTreeNodeStream nodes=new CommonTreeNodeStream(commonTree);
MyASTWalker walker=new MyASTWalker(nodes);
for (int i=0;i<100;i++) {
System.out.println(walker.calc());
}
antlr-interest at antlr.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090420/047f0cad/attachment.html
More information about the antlr-interest
mailing list