[antlr-interest] Variable definition annoyances

Terence Parr parrt at cs.usfca.edu
Fri Mar 25 11:08:54 PST 2005


On Mar 25, 2005, at 4:42 AM, Scott Stanchfield wrote:

> For 3.0, can we do something about variable definitions?
>
> I get pretty annoyed at things like:
>
> foo
>   { String a=null, b=null, c=null, d=null; }
>   : a=fee
>     b=fie
>     c=fo
>     d=fum
>     { doSomething(a,b,c,d); }
>   ;

Yep, that is really annoying.  I racked my brain over it for a long 
time.  It turns out you don't need to define them anymore.  You can do 
this:

start : r=rule { @r.i ... @r.s ... } ;

rule returns [int i, String s] : ... {@i=3; @s="foo";} ... ;

Cool eh?  Does this satisfy you?  It integrates very nicely with the 
dynamically scoped attributes and trees etc...

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com





More information about the antlr-interest mailing list