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
signature.asc
Description: OpenPGP digital signature
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
