[antlr-interest] Fwd: Simple question, Hard answer?

Thomas Brandon tbrandonau at gmail.com
Wed Sep 3 05:00:18 PDT 2008


On Wed, Sep 3, 2008 at 7:36 PM, Bill Mayfield <antlrinterest at gmail.com> wrote:
> Okay... but what if this isn't a lexer problem? Suppose I my input is
> only made up of 'o' and 'k'
>
> oooookooookkooo -> 1 match
> oookkoooookkoook -> 2 matches
>
> what would my grammar look like?
>
> grammar test;
>
> start   :       chaos* pattern* chaos*;
>
> pattern :       T1 T2 T2 T1;
>
> chaos   :       T1 | T2;
>
> T1      :       'o';
> T2      :       'k';
>
>
> This one compains that it can match multiple alternatives.
Posting the actual warning given is generally a good idea.
> I don't understand since I read it like: match any iteration of T1 or T2
> tokens followed by T1 T2 T2 T1 followed by any iteration of T1 or T2
> tokens....
>
Yes, but assuming you want the T1 T2 T2 T1 to match as a pattern
rather than a sequence of chaos's would lead to problems in other
cases so ANTLR is warning you either could match and thus it will
disable one of the alternates. I think it will automatically choose
pattern rather than chaos in which case you can ignore the warning as
it is doing what you want.

Tom.
>
> Thanks again :o)
>
>
> Kind regards,
> Bill
>


More information about the antlr-interest mailing list