This question in the antlr archives is the same one I have: "Is this now the correct practice where a tree walker is to be invoked repeatedly ?"
http://www.antlr.org/pipermail/antlr-interest/2009-March/033823.html The poster says that using BufferedTreeNodeStream instead of CommonTreeNodeStream solved his problem. This didn't work for me. However, calling the following method after each tree walk worked. Is this the preferred way to handle multiple tree walks or is there a better way? Also is the only disadvantage of using BufferedNodeStream increased memory? Does anyone know if this memory difference is significant. fyi I am getting about 4 times the performance on my test case with BufferedNodeStream. private void resetStream() { TreeNodeStream nodeStream=getTreeNodeStream(); if (nodeStream instanceof BufferedTreeNodeStream) ((BufferedTreeNodeStream)nodeStream).reset(); else if (nodeStream instanceof CommonTreeNodeStream) ((CommonTreeNodeStream)nodeStream).reset(); } On Mon, Apr 20, 2009 at 12:13 PM, Steve Souza <st...@stevesouza.com> wrote: > 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-inter...@antlr.org > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-interest@googlegroups.com To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address