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

Gavin Lambert antlr at mirality.co.nz
Fri Feb 1 12:52:08 PST 2008


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).



More information about the antlr-interest mailing list