[antlr-interest] Can subrules be set to 'n-to-m'?

John D. Mitchell johnm-antlr at non.net
Fri Mar 25 14:13:17 PST 2005


>>>>> "Martin" == Martin Probst <mail at martin-probst.com> writes:
[...]

>> (...)+[n,m]

>> with the ,m part optional.

> Uh, better make only the "m" optional, e.g.
>> (...)+[n,]
> Otherwise it might be mistaken as "exactly n times". Maybe this should
> indeed be the case for (...)+[n].

Yes, I meant that to mean 'exactly".  To be clear...

(XYZ)+[n,m]  means XYZ must occur anywhere from n through m times
(inclusive on both ends).

(XYZ)+[n]  means XYZ must occur exactly n times.

(XYZ)+[0,n]  should be an error telling people that they should b using:

(XYZ)*[0,n]  means 0..n occurrences.

(XYZ)*[n,m]  means 0, or n..m occurrences.

(XYZ)*[n]  means 0 or exactly n occurrences.

[Though, personally, I'm not sure that the last three cases are
justifiable to include in the Antlr core.  I'd like them for completeness
and consistency and would actually be using them but I know that I'm a
wacko. :-)]

> Also (...)[1,] looks at least understandable for me - maybe as an alias
> for (...)+.

Naw, if you're going to support an "at least" construct then you've gotta
make it more clearly distinct than that.  Something like:

(XYZ)+[n...]   or
(XYZ)+[n,...]   or
(XYZ)+[n,+]

Hope this helps,
		John


More information about the antlr-interest mailing list