[antlr-interest] How to return my own objects ?
Gavin Lambert
antlr at mirality.co.nz
Mon Aug 18 13:11:12 PDT 2008
At 10:51 18/08/2008, Le Lann Jean-Christophe wrote:
>expr returns [MyExpr expr] :
> ^( '+' e1=expr e2=expr) { $expr = new MyExpr("+",e1,e2);}
> | INT { $expr = new MyExpr(new
>String($INT.text));}
> ;
Technically, if you want the return value from that then instead
of using e1/e2 in your code you should be using $e1.expr /
$e2.expr.
>architecture returns [Architecture arch] :
> ^(ARCHITECTURE ID <skipped>)
> {$arch=new Architecture(new String(ID.text));}
Similarly here you should be using $ID.text, and wherever this is
being invoked from you should be using $something.arch.
If you use the proper syntax then ANTLR takes care of the
differences for you ;)
More information about the antlr-interest
mailing list