[antlr-interest] Way to send two different trees based on input to rule?
Terence Parr
parrt at cs.usfca.edu
Sat Nov 25 07:57:01 PST 2006
On Nov 25, 2006, at 5:47 AM, Brian DeVries wrote:
> Hello all,
>
> I have an ANTLR v3 parser rule that takes a boolean parameter, does
> some stuff, and outputs (part of) an AST. When that parameter is
> true, I want it to output a certain node in the tree, and something
> else when it's false.
a : A -> {p}? x
-> y
;
That should be in the manual...
Ter
> Is there a way to do this? I'm thinking semantic predicates, but
> the v2 documentation from the website states that predicates in the
> middle of the rule are validating, and I couldn't get the
> disambiguating one to work on another rule a few days ago (it was
> still treating it as a validating predicate).
>
> Toy example (should be syntactically right):
>
> rule [boolean b]
> : X y -> ^(R X y)
> ;
>
> I'm wanting something like
>
> rule [boolean b]
> : X y /* if $b == true */ -> ^(R X y)
> /* else */ -> ^(R Z y)
> ;
>
> Thanks!
> ~Brian
More information about the antlr-interest
mailing list