[antlr-interest] Re: ANTLR not generating correct end condition on greedy=false loop.

lgcraymer lgc at mail1.jpl.nasa.gov
Mon Jan 19 13:05:34 PST 2004


Daniel--

I think that you'd be much better off not using the "greedy" option,
which is a bit of a hack mainly intended for use in lexers.  From your
earlier message 

> This of course will give an invalid
> parse because the loop will stop at - and it will expect a RCURLY.
>
> To make this grammar work I have to write:
>
> a: LCURLY ( options { greedy=false; } : . )* RCURLY;
> b: PLUS ( options { greedy=false; } : . )* MINUS;
>
> so that the end condition is ok. Is there a way to make the above
> grammar
> work? Is there a good reason for this kind of limitation?

you can make your grammar easier to read by changing the above
definitions to

a :  LCURLY ( ~RCURLY )* RCURLY ;
b :  PLUS  ( ~MINUS )* MINUS ;

There are occasions when macros or "generic" rules would be
convenient, but then there comes the point at which you need to insert
actions.  Somehow, the "generic" aspects of the grammar start to
disappear.

--Loring

--- In antlr-interest at yahoogroups.com, "lachinois2002"
<lachinois at h...> wrote:
> Humm...
> 
> In that case I think macros would greatly improve the readability of 
> my grammar, since I am using a lot of non-greedy loops. It would 
> make a lot of sense in that context.
> 
> I'm using a 3rd party solution for macros, but do you think ANTLR 
> will have macro support with arguments anytime soon? Maybe for 
> version 3?
> 
> Daniel Shane


 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/antlr-interest/

To unsubscribe from this group, send an email to:
 antlr-interest-unsubscribe at yahoogroups.com

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




More information about the antlr-interest mailing list