[antlr-interest] Wildcard in tree grammar? - was validatingsemantic predicates
Harald M. Müller
harald_m_mueller at gmx.de
Fri Nov 30 14:48:17 PST 2007
Mhm ... but not for me. Also, I cannot see how *adding* another condition
would allow *more* alternatives to be parsed: I still get same result "no
viable ...".
The generated ifs also dont look too good, IMHO:
else if ( (LA2_0 == 6) && (( x || !x )) )
{
int LA2_2 = input.LA(2);
if ( (LA2_2 == DOWN) && ( x ) )
{
alt2 = 1;
}
else if ( (LA2_2 == UP) && ( !x ) )
{
alt2 = 2;
}
else
{
throw ...
}
This is exactly the same code as without the !x in the grammar, if one
removes the !x conditions; and they lead - in the case of x = false - to the
same branch, namely throw ...
Thx anyway!
Regards
Harald
> -----Original Message-----
> From: John B. Brodie [mailto:jbb at acm.org]
> Sent: Friday, November 30, 2007 11:34 PM
> To: harald_m_mueller at gmx.de
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Wildcard in tree grammar? - was
> validatingsemantic predicates
>
> I believe that you have to test the boolean condition on both
> sides of the alternate.
>
> Not sure whether or not that was Dr. Parr's intention.
>
> But it seems to work for me.
>
> >statement
> > : simpleStatement
> > |
> > ^('if' x=condition ( { x }? statement
> > | .
> > )
> > )
> > ;
>
> instead try:
>
> statement
> : simpleStatement
> |
> ^('if' x=condition ( { x }? statement
> | {!x }? .
> )
> )
> ;
>
>
>
>
> -jbb
>
More information about the antlr-interest
mailing list