[antlr-interest] Rewrite a list to a set of trees
Gavin Lambert
antlr at mirality.co.nz
Fri May 22 01:16:15 PDT 2009
At 17:58 22/05/2009, Gary R. Van Sickle wrote:
>var_decl_list
> : TYPENAME ids+=IDENTIFIER (',' ids+=IDENTIFIER)* -> ^(VAR_DECL
>TYPENAME IDENTIFIER)+
> ;
>
>If your rule can't be reduced to a one-liner like that though
(e.g.
>C declarations), things quickly get complicated, and I've yet to
>determine a good, general way of handling it. You'll probably
>want to look into ANTLR's rule parameters and return values in
>that case.
I haven't actually tested this, but another way I think you could
do that would be something like this:
var_decl_list
: t=TYPENAME! var_decl[$t] (','! var_decl[$t])*
;
var_decl[CommonToken typename]
: IDENTIFIER -> ^(VAR $typename IDENTIFIER)
;
More information about the antlr-interest
mailing list