[antlr-interest] v3 error: ANTLR could not analyze this decision in rule

F Reig fermin.reig at gmail.com
Wed Oct 3 04:38:41 PDT 2007


Hi,

I have a rule in v 2.7.6 that results in the error mentioned in the
subject when translated to v3. I'd be grateful if someone can suggest
an alternative.

The rule parses a list (possibly empty) of items separated by commas.
They are the arguments of a function call, with the twist that
arguments might be missing. For instance, all these are valid:

(); (a); (a,b); (,b); (a,)

Here's the rule in v2

args
   :   ( (maybe_arg COMMA!) =>
         maybe_arg (COMMA! maybe_arg )+
       | arg
       )?
   ;

arg  :   exp   {## = #([ARG,"ARG"], #arg);}   ;

// Return ARG even if the expression is not present
maybe_arg   :   (exp)?  {## = #([ARG,"ARG"], #maybe_arg);}    ;

Note: that parses the list itself, not the parentheses.

Here's my attempt at translating the rule into v3

args :  same as in v2

arg :   e=exp -> ^(ARG[$e.start] exp)  ;

maybe_arg  :   e=exp? -> ^(ARG[$e.start] exp?)   ;

This results in the message:

warning(205): v3.g:496:9: ANTLR could not analyze this decision in
rule args; often this is because of recursive rule references visible
from the left edge of alternatives.  ANTLR will re-analyze the
decision with a fixed lookahead of k=1.  Consider using "options
{k=1;}" for that decision and possibly adding a syntactic predicate.

Thanks,
Fermin


More information about the antlr-interest mailing list