[antlr-interest] Re: "return" in rule code

lgcraymer lgc at mail1.jpl.nasa.gov
Thu Nov 7 13:16:11 PST 2002


--- In antlr-interest at y..., "Paul J. Lucas" <dude at d...> wrote:
> Is it "OK" to have a "return" statement in a rule?
> 
> 	FOO
> 		: "foo" { if ( cond ) return; } "bar"
> 		;
> 
> Will the above match only "foo" if cond is true, i.e., abort the 
matching?
> 
> - Paul

Paul--

The right way to do this is with a semantic predicate:

FOO
         :
             "foo"  ( {cond}? "bar" | )
         ;

This is guaranteed to work; using "return" in an action could well 
bypass ANTLR tree construction (right now it doesn't, but it probably 
will in the next big--3.0--release when AST construction is 
optimized).

--Loring


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list