[antlr-interest] multiplicity in TreeParser

Olivier Lefevre lefevrol at yahoo.com
Tue Feb 26 17:07:17 PST 2008


Assuming a Java target, something along these lines should work:

example returns [List list]
@init { list = new ArrayList(); }
     : ^( TOKEN (x1=OBJ1 {list.add(x1);})+ (x2=OBJ2 {list.add(x2);})+ )
     ;

In other words if you want a list I think in a tree grammar context
you have to build it yourself because the x1 etc "collections" are
not held in collections but in trees. This is different from the
expression grammar context. Or did I misunderstand the question?

-- O.L.



More information about the antlr-interest mailing list