I am trying to write an AST interpreter / REPL. ANTLRv4 provides two very similar interfaces (ParseTreeVisitor and ParseTreeListener) to walk the parse tree. I cannot seem to find any major differences between them, and the documentation is rather sparse. Is one interface preferable to the other?
The interfaces are used for different purposes. The primary differences are as follows:
ParseTreeListener
void
. Any values collected for "return" by the listener must be held in fields or elsewhere.ParseTreeWalker
or a derived class).ParseTreeVisitor
T
, which may be Void
if the visitor methods do not return a value.visitChildren
and/or calls to visit
for specific children).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With