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

George S. Cowan cowang at comcast.net
Sun Mar 22 08:51:43 PDT 2009


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


> -----Original Message-----
> From: Terence Parr
> Sent: Saturday, March 21, 2009 2:57 PM
> To: ANTLR Interest Mailing List
> Subject: [antlr-interest] proposal: make .* and .+ always nongreedy
> 
> 
> http://www.antlr.org/jira/browse/ANTLR-392
> 
> any objections?
> 
> Ter
> 
> 
> 
> 



More information about the antlr-interest mailing list