[antlr-interest] Re: breaking out of a closure loop

lgcraymer lgc at mail1.jpl.nasa.gov
Tue Dec 11 17:20:42 PST 2001


I think that a better idiom is

 	{keepGoing}? otherRule

which works--it disambiguates "otherRule" from "NULL", which is a 
viable alt for STAR loops.

ANTLR does not internally distinguish between validating and 
disambiguating predicates.  I think that you are right that validating 
predicates merit inclusion in an upgraded error-handling mechanism:  
user defined exceptions at the grammar level (not in actions) would 
certainly be a convenience for error reporting.


--- In antlr-interest at y..., mzukowski at b... wrote:
> Ter, you need a disambiguating semantic predicate, yes?  Otherwise 
> exception is thrown on the assumption that it is a validating 
predicate.  So
> you have to have another alternative there.  I think the idiom I 
used was:
> (
> 	{keepGoing}? otherRule
> )+
> SOME_IMAGINARY_NEVER_GENERATED_TOKEN gives the loop a non-guarded
> alternative which will never be matched (because the lexer never 
> it) but gives the semantic predicate an alternative so the predicate 
> disambiguating instead of validating.  When keepGoing is false then 
> viable alternative will be found and the loop will break 
> For antlr 3 would it be possible to incorporate a $break() as an 
action?  Or
> some other appropriate distinction between a validating and 
> predicate?  People always get confused between those two anyways.  
And even
> in a loop with only one alternative in the loop it is appropriate to 
have a
> disambiguating predicate to break the loop.
> Actually the entire role of a validating predicate merits some 
thinking.  I
> don't think I have personally used them.  However, they could be 
part of a
> saner, broader error handling mechanism.
> Monty


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

More information about the antlr-interest mailing list