[antlr-interest] Tree grammar conditionally run subrule

Gavin Lambert antlr at mirality.co.nz
Thu May 29 02:21:33 PDT 2008


At 18:38 29/05/2008, Fridi wrote:
 >I have simply tried
 >
 >: ^(OR a = expression
 >	{
 >	  if (a)
 >	    return true;
 >	}
 >       b = expression
 >       {
 >	  $r = a || b;
 >       }
 >    )
 >
 >
 >... but that leads to mismatched tokens exception, and I guess 
that
 >is because the tokens (nodes) are not consumed as if it would 
run the
 >2nd. expression

How about this:

   ^(OR a=expression
     ( { $a }? => . { $r = true; }
     | b=expression { $r = $b; }
     )
   )

(I'm assuming that expression already returns a boolean.)



More information about the antlr-interest mailing list