[antlr-interest] Antlr regex support for {min,max}

Nigel Sheridan-Smith nbsherid at secsme.org.au
Sun Oct 9 22:10:58 PDT 2005



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Eric Crampton
> Sent: Monday, 10 October 2005 2:22 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Antlr regex support for {min,max}
> 
> Does Antlr provide a way to match a range of occurrences of a literal
> in a lexer? For example, in a modern egrep implementation, you can do:
> 
>    a[0-9]{2}c
> 
> which will match 'a' followed by exactly 2 digits followed by 'c'.
> 
>    a[0-9]{2,3}c
> 
> would match 'a' followed by 2 or 3 digits followed by 'c'. Any way to
> do that in Antlr? I know the second one could be written like so:
> 
>    a[0-9][0-9][0-9]?c
> 
> but the grammar I'm writing has a lot of occurrences of this and with
> more complicated Antlr expressions like ('0'..'9'). Repeating these
> everywhere makes the grammar very hard to follow and near as I can
> tell, Antlr doesn't provide the {min,max} construct.
> 
> Yeah, this is something pretty wacky I'm trying to parse. :-)  Might
> end up hand-coding it, but I'd rather avoid that.
> 

Hi Eric,

I believe Terence has added this to ANTLR 3.x, but in ANTLR 2.x you can use
a counter variable combined with a semantic predicate. Have a look through
the last few months of the list archive, as this has been discussed fairly
recently.

Nigel

--
Nigel Sheridan-Smith
PhD research student

Faculty of Engineering
University of Technology, Sydney
Phone: 02 9514 7946
Fax: 02 9514 2435



More information about the antlr-interest mailing list