[antlr-interest] Ambiguous grammar or Antlr?

Gavin Lambert antlr at mirality.co.nz
Fri Jul 3 03:52:02 PDT 2009


At 17:47 3/07/2009, Gary R. Van Sickle wrote:
 >But isn't the whole point of LL(*) to eliminate the need to do
 >exactly this sort of left-factoring?  Section 11.3 of Ter's
 >book gives essentially the former as an example of why LL(*)
 >makes it so you don't have to do a manual refactoring such
 >as the latter.

ANTLR v3 is *much* better at dealing with left-commonality than v2 
was, but it's still not perfect.  And the parser is better at it 
than the lexer.

But regardless, an LL(1)-safe lexer/parser will always give you 
better performance than something that requires a higher k, so 
left-factoring is usually beneficial anyway.

The main feature of LL(*) in ANTLR is that it automatically 
decides on an alt-by-alt basis what to set k to; it chooses the 
minimum it thinks it can get away with (unlike in v2, where you 
had to work it out yourself, or more commonly just set it at the 
global level and live with the performance loss).  Unfortunately, 
loops confuse it, and if the grammar isn't factored properly then 
it can sometimes choose too low a value.



More information about the antlr-interest mailing list