Reputation: 447
I'm using Antlr4, C# version under Visual Studio. Works nicelly.
AFAIK (but I may be wrong) Listeners and Visitors are used for similar tasks.
So, how to decide between them? Or can I use both? Note that all the samples I've found uses Listener OR Visitor, but not both...
Upvotes: 1
Views: 1961
Reputation: 158
In my opinion he visitor is a good choice because you have full control of the traversal
Here is quote from the book "The Definitive ANTLR 4 Reference"
The biggest difference between the listener and visitor mechanisms is that listener methods are called by the ANTLR-provided walker object, whereas visitor methods must walk their children with explicit visit calls. Forgetting to invoke visit() on a node’s children means those subtrees don’t get visited
If you translate the input to a lower level, e.g. virtual machine instructions, both patterns may be useful.
Upvotes: 1