문제

  • 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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top