[antlr-interest] On "How to remove global backtracking"

Gary R. Van Sickle g.r.vansickle at att.net
Sun Mar 8 19:05:34 PDT 2009


Hi guys,

From
<http://www.antlr.org/wiki/display/ANTLR3/How+to+remove+global+backtracking+
from+your+grammar>:

"Left-factoring
Now to the three real tools against non-determinism. The first is
left-factoring. Look at the following rule:

a : L b
   | L c
   ;
As you can see, the two L at the beginning prevent that ANTLR can decide
which path is the right path. [...]"

Is this actually true?  The proposed "manual" correction is of course:

"a : L (b | c)
  ;"

Why would this not be trivially reduced automatically by ANTLR, maybe with a
"warning" that this could be reduced in the input grammar?  Even if "L" here
is not a terminal but is intended to be either a terminal or non-terminal,
aren't these two variations in all cases exactly equivalent?

-- 
Gary R. Van Sickle



More information about the antlr-interest mailing list