[antlr-interest] What does " The following alternatives can never be matched" mean

David-Sarah Hopwood david-sarah at jacaranda.org
Wed Dec 2 14:50:10 PST 2009


Gavin Lambert wrote:
> At 20:30 2/12/2009, David-Sarah Hopwood wrote:
>>You probably want these to be lexer rules, i.e.
>>
>>  prog     : command+ ;
>>  command  : (Function | Var)+ ;
>>
>>  Function : ('A'..'Z')+ ',' ;
>>  Var      : ('A'..'Z')+ ;
>>  WS       : ( '\t'|' '|'\r'|'\n'|'\u000C' )+ { $channel = HIDDEN;
>>} ;
> 
> Actually it's probably better to keep function/var out of the lexer:
> 
> prog : command+ ;
> command : (function | var)+ ;
> function : ID COMMA ;
> var : ID ;
> 
> fragment Letter : 'A'..'Z';
> COMMA : ',' ;
> ID : Letter+ ;
> WS : ( '\t'|' '|'\r'|'\n'|'\u000C' )+ { $channel = HIDDEN; }

That depends on whether ',' has to be immediately after the letters,
(as in my solution) or whether there can be intervening whitespace
(as in your solution).

Also, the <command> rule in your solution is not left-factored, so it
will give a nondeterminism warning (which should be treated as an error).
It would have to be something like

  command : (ID COMMA?)+ ;

as you suggested in your previous post.

Both solutions also have another ambiguity, because a <command> is
a sequence of (function | var) and a <prog> is a sequence of <command>s.
An explicit command separator is probably needed to resolve that.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 292 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20091202/d41d7be3/attachment.bin 


More information about the antlr-interest mailing list