[antlr-interest] The problem of return struct

chain one chainone at gmail.com
Sun Nov 30 23:47:40 PST 2008


options
{
output=AST;
}

entity_id returns [String eid]
@init{ eid=null; }
     : { isFirst }? id=IDENT { eid=id.getText();
/*addId(eid,ENTITY_IDENT);*/ } -> ^(ENTITY_ID[]  $id)
             |  id2=ENTITY_IDENT { eid=id2.getText();$id2.setType(IDENT);} ->
^(ENTITY_IDENT[] $id2)
             ;

variable eid would be undefined when compiling the generated Java code.
I checked the Java code, and found the reason was because eid was a member
variable of the return struct, so variable eid could not be used in method
directly,check the following code out:

//code start
   public static class entity_id_return extends ParserRuleReturnScope {
        public String eid;
        Object tree;
        public Object getTree() { return tree; }
    };

    public final testbasetypeParser.entity_id_return entity_id() throws
RecognitionException {
         eid=null;

//code end


I am looking for a method that could avoid this kind of problem (not modify
the Java code directly : ) )
Anyone who knows this kind of method please let me know, your help is
appreciated.
Thanks very much.


Best Regards,
chainone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081201/4d2e389f/attachment.html 


More information about the antlr-interest mailing list