You want gated semantic predicates to turn on rules. However, that is the
wrong approach in this case. You should accept and parse both sides even
though only one is legal, then reject the code with a semantic error
rather than a syntax error, which would confuse the user.  You get "cannot
both precede and follow a dfdd with a gffgfgf" instead of "Unexpected
'gffgfgf'"

Jim

> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Roy Metzger
> Sent: Thursday, July 14, 2011 4:12 PM
> To: [email protected]
> Subject: [antlr-interest] turning rules on/off?
>
> Hi all,
>
> Let's say I have something like this:
>
> rule: ( 'stuff' e1=expression)?
> statement
> ('stuff' e2=expression)? ;
>
> Now, I would like to know is there a way to dynamically flip rules
> on/off. For example, when
> e1 is present e2 is not, and when e2 exists, e1 does not.
>
>
> Based on my research I found that predicates may be of help to me(of
> course, aside from refactoring), but
>
> I'm really not sure how to use them, as I'm still very new to antlr.
>
>
> Could something like this work:
> rule
> @init{boolean b=false;}:
>
> ( 'stuff' e1=expression{b=true;})?   {b}?=>expression statement (
> 'stuff' e2=expression{b=false;})?   {!b}?=>expression
>
> I would really appreciate if some of more experienced users would give
> me hints on this one.
>
> Thanks for any help
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to