[antlr-interest] problem with tree parsing -> don't get a tree walker to work correctly

Peter Götz peter.goetz at gutefrage.net
Tue Apr 17 02:05:44 PDT 2012

Hi Jim, 

thanks for your answer. So it seems my problem is a common one, if you don't even have to look at my rules. ;) 

>  LBRACKET (e=expr (COMMA e=expr)*)? RBRACKET
> But should look like this:
>  LBRACKET (e+=expr (COMMA e+=expr)*)? RBRACKET

But it seems you have been right. I have not managed to get it to work, though, because in my grammar options I can not give an output value, because my output value is of my own type. But the error message when not giving the output option and Google brought me to the correct solution. I know have created a separate rule to parse the function parameters and its return value is being added to the function node: 

params returns[List result]
        @init { $result = new ArrayList(); }
        : (e=expr { $result.add(e); })+

This seems to work fine and is ok for me. If anyone has some information for me if this is not the optimal solution and could be implemented in a better way, I would be happy to receive this knowledge and improve my grammar - it starts being fun and making sense. :)

Thanks for your help and best regards, 


More information about the antlr-interest mailing list