[antlr-interest] [3.1.1] ANTLR3_MIN_TOKEN_TYPE define possibly incorrect
Sven Van Echelpoel
sven.van.echelpoel at empolis.com
Fri Mar 27 01:46:48 PDT 2009
> >
> It's difficult to see exactly from your examples of course, but I think
> that that is what you want to do. Assuming that you are only looking for
> C C, then a simple syntactic predicate shoudl suffice:
Right, I had forgotten about those. Up until now I had no use for them.
I guess I must reread the relevant section in the book again :-)
>
> element :
> A
> | B
> | C ( (C)=> C {special stuff; }
> | {something else do nothing}
> )
> | etc.
>
> You can also set a flag to say whether you are in an alternation by using a scope at the element_list level like this:
>
> element_list
> scope
> {
> ANTLR3_BOOLEAN isAlternation;
> }
> @init
> {
> $element_list::isAlternation = ANTLR3_FALSE;
> }
> :
>
>
> ...
>
> alternation
>
> : ^( ALTERNATION { $element_list:isAlternation = ANTLR3_TRUE; } group+ )
>
> and then testing that flag.
>
> This might not be exactly what you are looking for, but it is close I think.
Indeed it is. It gave me an idea. I can keep a flag at alternation scope
that tells me whether the alternation is over C's only. I can then use
this in the grammar for the case C ALT C
Thanks for the insights,
Sven
More information about the antlr-interest
mailing list