O'Reilly logo

The Definitive ANTLR 4 Reference, 2nd Edition by Terence Parr

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parse-Tree Listeners and Visitors

ANTLR provides support for two tree-walking mechanisms in its runtime library. By default, ANTLR generates a parse-tree listener interface that responds to events triggered by the built-in tree walker. The listeners themselves are exactly like SAX document handler objects for XML parsers. SAX listeners receive notification of events like startDocument and endDocument. The methods in a listener are just callbacks, such as we’d use to respond to a checkbox click in a GUI application. Once we look at listeners, we’ll see how ANTLR can also generate tree walkers that follow the visitor design pattern.[13]

Parse-Tree Listeners

To walk a tree and trigger calls into a listener, ANTLR’s runtime provides class ParseTreeWalker ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required