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

David-Sarah Hopwood david-sarah at jacaranda.org
Tue Dec 1 23:30:40 PST 2009


qinglangee wrote:
> Hi all. 
>  
> I had a toy grammer,
> 
> grammar cub;
> 
> prog:   (command)+ ;
> command	: (function |var)+;
> function : (Letter)+',';
> var : (Letter)+;
> Letter  :	'A'..'Z';
> WS	:	( '\t'|' '|'\r'|'\n'|'\u000C' )+ 	{ $channel = HIDDEN; } ;
> 
> I expected it can recognise text like:
> 
> Funone,varone
> Funtwo,vartwo
> 
> Here is a tool run: 
> [11:14:04] warning(200): cub.g:4:25: Decision can match input such as
> "Letter" using multiple alternatives: 1, 2, 3
> As a result, alternative(s) 3,2 were disabled for that input
> [11:14:04] error(201): cub.g:4:25: The following alternatives can never be
> matched: 2
> 
> I didn't know who can never be matched, and why?

'command' starts with Letter+ in both its function and var alternatives,
so they can't be distinguished by an LL parser.

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; } ;

-- 
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/eb2e1bf6/attachment.bin 


More information about the antlr-interest mailing list