[antlr-interest] Possible bug in swapping intermediary terminal?

Dejas Ninethousand dejas9000 at gmail.com
Fri Feb 1 12:57:48 PST 2008


 changing IDENTIFIER (PACKAGE_SEPARATOR IDENTIFIER)+ to IDENTIFIER
(PACKAGE_SEPARATOR IDENTIFIER)* produces the same problem.  Though that is a
good point about the whitespace... I had not considered that.

-- Dejas

On Feb 1, 2008 2:52 PM, Gavin Lambert <antlr at mirality.co.nz> wrote:

> At 09:29 2/02/2008, Dejas Ninethousand wrote:
>
> >type_identifier
> >     : IDENTIFIER
> >     |
> >     IDENTIFIER (PACKAGE_SEPARATOR IDENTIFIER)+
> >     ;
>
> It's generally a bad idea to have the same left-prefix in
> different alts, since ANTLR has a tendency to fall back on LL(1)
> behaviour.  Try rewriting this like so:
>
> type_identifier
>     : IDENTIFIER (PACKAGE_SEPARATOR IDENTIFIER)*
>     ;
>
> Incidentally (and assuming that you've got a standard
> hidden-channel WS rule), by moving this pattern into the parser
> from the lexer you've instantly said that these inputs are still
> valid type_identifiers:
>   "foo.bar.Dec"
>   "foo.         bar  .    Dec"
>   "foo   .
>           bar.
>      Dec"
>
> If that's not desired behaviour, then you should put it back into
> the lexer (since the WS rule is a sibling of other lexer rules,
> you have to explicitly mention when WS is allowed within another
> lexer rule).
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080201/424a0f2f/attachment.html 


More information about the antlr-interest mailing list