[antlr-interest] Ambiguous grammar or Antlr?
    Gary R. Van Sickle 
    g.r.vansickle at att.net
       
    Thu Jul  2 22:47:30 PDT 2009
    
    
  
Jim Idle wrote:
[snip] 
> Even with backtracking, you still need to know something 
> about LL(k) and parsing etc, and switching on backtrack mode 
> will hide all your problems. It also means, as you have found 
> out, that in the event of a syntax error, you cannot 
> determine much  about the location of your error.
> 
> Basically, you will need to left factor at least some parts 
> of your grammar. In this case, if you have something like:
> 
> | ID
> | ID '(' expr ')'
> | ID something else
> 
> and (probably more complicated than that is your issue), then 
> look to do:
> 
> | ID (  '(' expr
>          | something
>       )?
> 
> and so on.
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.  In fact, that section makes the argument
that one should *not* do the left-factoring manually, if for no other reason
than to maintain the readability of the grammar.
-- 
Gary R. Van Sickle
 
    
    
More information about the antlr-interest
mailing list