[antlr-interest] set max number of characters in a string literal

Bill Mayfield antlrinterest at gmail.com
Fri Sep 12 11:46:29 PDT 2008


Maybe not of interest to you, since you're using antlr 2.7. There is a
similar example of your problem in the ANTLR 3.0 book.

You can solve your problem using a validating predicate:

data: ( c+=CHARACTER)+  {$c.size()<=4}? ;


I know there is no concept of the += in antlr 2.x but maybe you can
adapt the example to work with 2.7 also...


Good luck!

Bill



On Fri, Sep 12, 2008 at 5:48 AM, Olya Krachina <okrachin at purdue.edu> wrote:
> Hello,
> I am working on a lexer and i was wondering how i could set a max limit on the
> number of characters that make up a string literal, i.e. it is valid when there
> are n (let's say n = 20) or less chars. I tried setting lookahead to 20 (options
> k = 20) but it did not have any effect. I am using antlr 2.7.
>
> thanks in advance for any ideas on this,
> Olya
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>


More information about the antlr-interest mailing list