[antlr-interest] ANTLR3 AST construction with optionsandalternatives

Foolish Ewe foolishewe at hotmail.com
Mon Nov 13 10:40:05 PST 2006


Hi Dave and ANTLRInterest folks:

I'm not sure about what the ANTLR folks call these things so just
to be clear, if we have a rule like the one I originally suggested,
b and c+ are what I'll call atributes.  I'm guessing that Dave
refers to the + suffix as the cardinality of the attribute.

I wasn't sure, it isn't clear to me what the + suffix implies for
attributes, my gut reaction was that it was intended for attributes
that occur a variable number of times.  If + means one or more repetitions,
like it does for parsing and lexing, and if (from your the remainder of your 
reply)
we can use '?' for zero or one times, does that mean we can use other 
cardinalities,
i.e.  '*' for zero or more times as well?   Are empty/uninitialized 
attributes (assuming * or ?
cardinality) omitted from the tree if they are listed in the right hand side 
of the ->
operator in an AST rule?

If that is true, I'll have to go back and look to see if I missed something 
obvious in the wiki or if
the Wiki could use a more explicit hint.

I've been busy today refactoring grammars, but perhaps my limited 
understanding of
ANTLR compelled me to do more work than I had to.  It would be really nice 
if I could
get ANTLR to do that so I would not have to.

Regards:

Bll M.
>From: David Holroyd <dave at badgers-in-foil.co.uk>
>To: antlr-interest at antlr.org
>Subject: Re: [antlr-interest] ANTLR3 AST construction with 
>optionsandalternatives
>Date: Mon, 13 Nov 2006 18:21:13 +0000
>
>On Mon, Nov 13, 2006 at 05:26:12PM +0000, Foolish Ewe wrote:
> > a: b=b (c+=C)?->^(A $b $c+); // Doesn't seem to work if C is not scanned
>
>I dunno if this is the problem or not, but if 'C' only appears once on
>the left of the rewrite above, wouldn't you write 'c=C', rather than
>'c+=C'?  I've not used the += systax, so I'm not entirely sure.
>
>Also, my simplistic unserstanding is that cardinality should 'match'
>(sort of) on the left and the right of the rewrite, so I would be doing
>something like,
>
>   a: b=b (c=C)?->^(A $b $c?);
>
>(i.e. giving the $c ref a '?' rather than a '+')
>
>finally, I think that in such a simple rule, you don't need to
>explicitly label each of the values, so you could rewrite it thus,
>
>   a: b C? -> ^(A b C?)
>
>
>I've not tested any of that though.  ;)
>
>
>ta,
>dave
>
>--
>http://david.holroyd.me.uk/

_________________________________________________________________
Try the next generation of search with Windows Live Search today!  
http://imagine-windowslive.com/minisites/searchlaunch/?locale=en-us&source=hmtagline



More information about the antlr-interest mailing list