[antlr-interest] Possible bug in swapping intermediary terminal?
Mark Volkmann
r.mark.volkmann at gmail.com
Fri Feb 1 12:38:57 PST 2008
On Feb 1, 2008 2:29 PM, Dejas Ninethousand <dejas9000 at gmail.com> wrote:
> 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?
I hate it when people say "Works for me!" ;-)
Unfortunately that's what I have to say here. I ran the ANTLRWorks
debugger on the following grammar and gave it your input of
"foo.bar.Dec" and it created the correct parse tree.
grammar package;
type_identifier
: IDENTIFIER
| IDENTIFIER (PACKAGE_SEPARATOR IDENTIFIER)+
;
IDENTIFIER
: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*
;
PACKAGE_SEPARATOR: '.';
--
R. Mark Volkmann
Object Computing, Inc.
More information about the antlr-interest
mailing list