[antlr-interest] proposal: make .* and .+ always nongreedy

Andreas Meyer andreas.meyer at smartshift.de
Sun Mar 22 19:05:52 PDT 2009


FYI, the gazelle parser project (prototype) also aims at something 
similar, with slightly different syntax. Having non-greedy parsing in 
ANTLR also at the grammar level would be really useful, especially for 
languages without reserved identifiers. But I guess it's not an easy 
hack that one would do over a weekend.

George S. Cowan schrieb:
> Certainly make '.*' and '.+' consistent across all the grammar types, one
> way or the other.
>
> The real issue with '.*' and '.+' is of course trading off the increase of
> confusion that beginning ANTLR users already have over the whole issue of
> greedy/nongreedy with the need for expert users to specify grammar rules
> concisely. 
>
> The problems with this tiny piece of the language, the fact that you raised
> the issue rather than just doing it, and the fact that several people have
> taken the time to bother about replying to your note, leads me to think that
> the whole greedy/nongreedy distinction is important, and it therefore needs
> to be raised to a higher level and not buried in the options. Also note that
> it is an option that applies only to iterative subrules and therefore is an
> integral part of iteration. My limited experience with ANTLR does not give
> me any special authority to make the following recommendation, so take it as
> a strong statement made to clearly raise the issue for your consideration: 
>
> Every time we look at an iterative subrule, we need to be reminded whether
> it is greedy or nongreedy; that is, we need separate operators for greedy
> vs. nongreedy iteration.
>
> I suggest deprecating the current notation and using:
>   (...)** and (...)++ for greedy
>   (...)|* and (...)|+ for nongreedy 
>     (or some other notation that indicates "stop me, quick")
>
> I know this is a change to the whole tradition of EBNF and regular
> expressions, so your thoughts, flames, and groans will all be appreciated.
>
> George
>   



More information about the antlr-interest mailing list