[antlr-interest] limit the number of characters in a string

Tim Halloran hallorant at gmail.com
Tue Sep 23 09:37:50 PDT 2008


Well, since 32 isn't that big you can use brute force.  Below is an example
that gives you identifiers that are no longer than 32 characters need to
start with a letter and then can have letters, numbers, or underscores.

grammar Example;

ID     :    AL
        ALN? ALN? ALN? ALN? ALN?
        ALN? ALN? ALN? ALN? ALN?
        ALN? ALN? ALN? ALN? ALN?
        ALN? ALN? ALN? ALN? ALN?
        ALN? ALN? ALN? ALN? ALN?
        ALN? ALN? ALN? ALN? ALN?
        ALN?
    ;

AL    : 'a'..'z' | 'A'..'Z';
ALN    : AL | '_' | '0'..'9';

Hope this helps,
Tim

On Tue, Sep 23, 2008 at 11:30 AM, waqas javed <waqasjaved at gmail.com> wrote:

>
> Hi,
>
>   I am writing a parser in antlr. Can you tell me how I can limit the
> number
> of characters in string. Actually I want to limit the max number of
> characters
> for an identifier to 32.
>
>   I am using the comman ('a'..'z')+ but this dont put any restriction on
> the
> max number of characters that can be there in an identifier.
>
> regards,
>
> waqas
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080923/2bfea5a9/attachment.html 


More information about the antlr-interest mailing list