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

Sharing Information Among Event Methods

Whether we’re collecting information or computing values, it’s often most convenient and good programming practice to pass around arguments and return values, rather than using fields or other “global variables.” The problem is that ANTLR automatically generates the signature of the listener methods without application-specific return values or arguments. ANTLR also generates visitor methods without application-specific arguments.

In this section, we’re going to explore mechanisms that let event methods pass data around without altering the event method signatures. We’ll build three different implementations of the same simple calculator based upon the LExpr expression grammar from the previous section. ...

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