[antlr-interest] turning rules on/off?

John B. Brodie jbb at acm.org
Thu Jul 14 16:33:01 PDT 2011


Greetings!

On Thu, 2011-07-14 at 16:11 -0700, Roy Metzger wrote:
> 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. 
> 

I probably do not actually understand your question. But perhaps you do
not really need predicates...

rule :
    ( 'stuff' expression statement ) 
  | ( statement 'stuff' expression )
  ;

> 
> 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





More information about the antlr-interest mailing list