[antlr-interest] breaking out of a closure loop

Terence Parr parrt at jguru.com
Tue Dec 11 13:37:50 PST 2001


On Tuesday, December 11, 2001, at 11:36  AM, praveenray wrote:

> Is it possible to break out of a ()* or ()+ loop explicitly? I mean,
> Can I use 'break' statement inside the loop like this:
>
> class myParser extends Parser;
> somerule
> { bool bQuit=false; }
>       :  SOME_TOKEN
>             (
>               bQuit = otherRule
>               { if (bQuit) break; }
>             )+
>            END_TOKEN
>         ;
> otherRule returns [bool bRet]
> { bRet = false; }
>                              : A B
>                                ( C | D {bRet=true;}
>                                );
>
>  Will it have any side effects? If yes, what is a safe way to break
> out of a loop after I have seen some special character?

"break" works but is not a good idea.  The grammar analysis has no idea 
what you do in actions.  Better to use a semantic predicate 
{!isSpecialChar(...)}? to tell it when to terminate.

Ter
--
Chief Scientist & Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org


 

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



More information about the antlr-interest mailing list