[antlr-interest] Dealing with lists in a tree grammar action

Kay Roepke kroepke at classdump.org
Thu Jul 12 23:12:54 PDT 2007


On Jul 13, 2007, at 4:16 AM, Cameron Esfahani wrote:

> Richard Clark, in his response, suggested something that seems to  
> work.  It's not as clean as I'd like, but it does look like it works:

Yes, that's the only way to do it right now. not really all that  
different from your original, don't you think?

orig:
elements returns[ pANTLR3_VECTOR List ]
	:	v += value+
		{
			$List = $v;
		}
	;

richard's suggestion:
elements returns[ pANTLR3_VECTOR List ]
@init { $List = new pANTLR3_VECTOR; }
  : ( value
      { /* Whatever you want in here, e.g.: */ append($value.value,  
$List); }
    )+
  ;

It's essentially what ANTLR would generate anyway.

But I agree that the feature should be supported, and I'm sure it  
will be :)

cheers,
-k
-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list