[antlr-interest] Collecting disparate subtrees into one tree?

Gavin Lambert antlr at mirality.co.nz
Wed Jul 1 13:16:43 PDT 2009


At 00:06 2/07/2009, jared.bunting at peachjean.com wrote:
 >It's been awhile since I've written grammars, but what about:
 >
 >code: (proc | func)*
 >  -> ^(CODE ^(PROCS proc*) ^(FUNCS func*))
 >
 >I seem to recall that this works fairly well...

And if it doesn't, you can try the more explicit variant:

code : (p+=proc | f+=func)*
   -> ^(CODE ^(PROCS $p*) ^(FUNCS $f*))
   ;

(Or leave out the PROCS/FUNCS nodes if you just want to reorder 
the procedures/functions without actually grouping them in a 
subtree.)



More information about the antlr-interest mailing list