Question

  • I understand that Antlr generates a tree walker and I can sub-class the BaseListener to act when the tree walker traverses over key items in the parse tree.
  • I understand that I can also create my own visitor, by sub-class BaseVisitor to navigate the parse tree in my own way.

Can I have my listener that responds to my own visitor?
I think I made a boo-boo and placed my application code unnecessarily in my sub-classed visitor.

I now believe the visitor should only visit and my listener should trigger events in my application code.

I think I got a little bit muddled in my implementation.

Was it helpful?

Solution

Sure. you can create whatever listener interface you want and then create a visitor that fires events to your listener. It's pretty inefficient however. Just dump your visitor and have the standard tree walker fire events at your listener :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top