[antlr-interest] how can i return a string including a regular express?

Jim Idle jimi at temporal-wave.com
Sat Nov 22 19:18:33 PST 2008


On Sat, 2008-11-22 at 20:31 -0600, Su Zhang wrote:

> HI everyone,
> 
> the problem is, I want to return a string which includes a regular
> express, like  i1=id1'(' i2=id1 ( ',' i3=id1)* ')', on the left of
> equals are label variables which are not included in the return
> string, and I use the method {String k=','+$i3.text;
> $p=$i1.text+'('+$i2.text + k*+')';} to assemble the return value p,
> but it won't work, it says that the * cannot be applied in this kind
> of express, so does everyone know a method to handle this kind of
> problem?


That's because it can't be applied like that ;-). * means zero or more
instances, so you want to put the action for $i3 within the * construct:

returns [String retStr]
... ( ',' i3=id1  { $retStr += $i3.text; } )* ...

Jim


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081122/f2434a3b/attachment.html 


More information about the antlr-interest mailing list