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

Naveen Chawla naveen.chwl at googlemail.com
Thu Oct 1 05:24:07 PDT 2009


Thanks so much! Yes, I tried complement: object object? coincidentally just
before I read your message and it worked. Good news is that in the real
grammar they ARE actually equivalent. But is there no way of making
'indirectObject' and 'object' appear as they are in the end structure if
there are 2 'object's in a row (they have slightly different meanings even
though syntactically the same)? Would a syntactic predicate solve this? For
example, complement: (indirectObject object)=>indirectObject object |
object; Is this the right one? (it doesn't seem to work on ANTLRWorks) Many
many thanks, N

2009/10/1 Gavin Lambert <antlr at mirality.co.nz>

> 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. :)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091001/97e232ef/attachment.html 


More information about the antlr-interest mailing list