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

Dejas Ninethousand dejas9000 at gmail.com
Fri Feb 1 12:29:39 PST 2008


Hi,

I'm having a problem getting a grammar to to accept "foo.bar.Dec" and I'm
not sure why.  I think it may be a bug.  Consider my initial grammar:

type_identifier
    : IDENTIFIER
    |
    TYPE_IDENTIFIER_FULL
    ;

IDENTIFIER
    : ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*
    ;

PACKAGE_SEPARATOR
    :    '.'
    ;

TYPE_IDENTIFIER_FULL
    : IDENTIFIER (PACKAGE_SEPARATOR IDENTIFIER)+
    ;

This grammar accepts the "foo.bar.Dec" input no problems.  However, I wanted
to modify the grammar to eliminate the the intermediary TYPE_IDENTIFIER_FULL
terminal by taking its rhs and allowing it to directly derive from
type_identifier:

type_identifier
    : IDENTIFIER
    |
    IDENTIFIER (PACKAGE_SEPARATOR IDENTIFIER)+
    ;

IDENTIFIER
    : ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*
    ;

PACKAGE_SEPARATOR
    :    '.'
    ;

Now when I give ANTLRWorks the same "foo.bar.Dec" to interpret, it builds
the tree :

<grammar XXX>
type_identifier
foo
.
bar
.
Dec
NoViableAltException


... and I don't understand why.  These grammars seem equivalent to me.  Is
there something I'm not seeing or is this a bug?

Thanks,
Dejas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080201/bbe86d10/attachment.html 


More information about the antlr-interest mailing list