[antlr-interest] Unreachable production

Austin Hastings Austin_Hastings at Yahoo.com
Sun Mar 30 14:43:12 PDT 2008


Because your "Name" entry starts with an upper-case letter, it is 
considered a GRAMMAR token instead of a PARSER rule.

Grammar tokens cannot purely include other grammar tokens, the way yours 
does, without getting warned -- the Name token will match every possible 
ID token, so you will never see any ID tokens in your parser.

If you meant for that to be true, then call ID and QW "fragments" of the 
overall Name token using the 'fragment' keyword:

fragment ID : ('a'..'z'|'A'..'Z')+ ;

If you meant for "name" to be a parser rule instead of a grammar token, 
and for ID and QW to be tokens, then you have to start it with a 
lower-case letter:

name : ID | QW ;

=Austin


andrei.majidian at bt.com wrote:
>
> Hi
>
> I am trying the Interpreter for the following grammar Name.g
>
> _____________________________________________
> grammar Name;
>
> start: wordList ;
>
> wordList: '[' Name (',' Name)* ']';
>
> Name: ID | QW;
>
> ID: ('a'..'z'|'A'..'Z')+ ;
> QW: '"' ('a'..'z'|'A'..'Z') (' '|'a'..'z'|'A'..'Z')* 
> ('a'..'z'|'A'..'Z') '"';
> WS: (' '|'\t' |'\r'|'\n')+ {skip();} ;
> ____________________________________________________
>
> With the following input:
>
> ["wild animal", "friendly", timid]
>
> It gave me the following Warning in the console
>
> "[21:52:57] warning(208): Name.g:10:1: The following token definitions 
> are unreachable: ID,QW
> [21:52:57] Interpreting…"
>
> What does this mean? The parse-tree is correctly produced. I don't 
> understand the warning.
>
> Thanks
>
> Andrei
>



More information about the antlr-interest mailing list