[antlr-interest] How to return my own objects ?

Le Lann Jean-Christophe jean-christophe.lelann at orange.fr
Sun Aug 17 15:51:24 PDT 2008


Hello,

I am struggling to return my own objects in the rules (v3.1). Normally 
this is obvious like :

expr returns [MyExpr expr] :
    ^( '+' e1=expr e2=expr) { $expr = new MyExpr("+",e1,e2);}
    | INT                   { $expr = new MyExpr(new String($INT.text));}
        ;
this perfectly generates (MyExpr returned) :
// DumpModified.g:8:1: expr returns [MyExpr expr] : ( ^( '+' e1= expr 
e2= expr ) | INT );
    public final MyExpr expr() throws RecognitionException {

but in a bigger grammar in which I have this rule :

architecture returns [Architecture arch] :
                    ^(ARCHITECTURE ID <skipped>) 
            {$arch=new Architecture(new String(ID.text));}

the generated code is :

// Walker.g:23:1: architecture returns [Architecture arch] : ^( 
ARCHITECTURE ID <skipped>) ;
    public final Walker.architecture_return architecture() throws 
RecognitionException {

==> "Walker.architecture_return" returned while I expected "Architecture"

What I am missing ? Could you explain or give me a pointer (I have the 
book) ?

Thx
JCLL



More information about the antlr-interest mailing list