January 2013
Intermediate to advanced
328 pages
8h 5m
English
To illustrate the event granularity problem, let’s try to build a simple calculator with a listener for the following expression grammar:
| | grammar Expr; |
| | s : e ; |
| | e : e op=MULT e // MULT is '*' |
| | | e op=ADD e // ADD is '+' |
| | | INT |
| | ; |
As it stands, rule e yields a fairly unhelpful listener because all alternatives of e result in a tree walker triggering the same enterE and exitE methods.
| | public interface ExprListener extends ParseTreeListener { |
| | void enterE(ExprParser.EContext ctx); |
| | void exitE(ExprParser.EContext ctx); |
| | ... |
| | } |
The listener methods would have to test to see which alternative the parser matched for each e subtree using ...
Read now
Unlock full access