[antlr-interest] Left factor? Syntactic predicates? Or another solution?

Gavin Lambert antlr at mirality.co.nz
Thu Oct 1 04:48:03 PDT 2009


At 23:13 1/10/2009, Naveen Chawla wrote:
>       complement: indirectObject? object;
>
>       indirectObject :  nounPhrase;
>
>       object : nounPhrase;
>
>       nounPhrase : 'the' adjectivePhrase? 'noun';
>
>      adjectivePhrase : '<Ving>' complement?;
>
>gives
>
>"error(211): predicate.g:7:14: [fatal] rule complement has 
>non-LL(*) decision due to recursive rule invocations reachable 
>from alts 1,2.  Resolve by left-factoring or using syntactic 
>predicates or using backtrack=true option."

The problem with this is that at the left edge of complement, it 
needs to evaluate whether indirectObject is present or not.  To do 
that, it attempts to match a nounPhrase, which will attempt to 
match an adjectivePhrase, which brings it right back to the left 
edge of complement -- and since that's optional too, it has to 
continue scanning forward into a death spiral.

As written here, you should be able to fix it by switching the 
optionality in the complement rule:
   complement: object object?;

I suspect that in your real grammar the indirectObject and object 
rules aren't actually equivalent though, so this may not help 
much. :)



More information about the antlr-interest mailing list