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

qinglangee zcqingdao at 163.com
Wed Dec 2 00:40:56 PST 2009




David-Sarah Hopwood wrote:
> 
> 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
> 
> 
>  
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
> 

It works. tks .Maybe I shoule understand what is a  LL parser first.

-- 
View this message in context: http://n2.nabble.com/What-does-The-following-alternatives-can-never-be-matched-mean-tp4097824p4098622.html
Sent from the ANTLR mailing list archive at Nabble.com.


More information about the antlr-interest mailing list