[antlr-interest] turning rules on/off?

Roy Metzger antlrmen at yahoo.com
Thu Jul 14 16:11:49 PDT 2011


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


More information about the antlr-interest mailing list