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

Jim Idle jimi at temporal-wave.com
Thu Oct 1 07:16:26 PDT 2009


You would have to use ((object object)=>object)? Which is expensive and is using a hammer to crack a nut ;-)

 

Jim

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Naveen Chawla
Sent: Thursday, October 01, 2009 5:24 AM
To: Gavin Lambert
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Left factor? Syntactic predicates? Or another solution?

 

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/7be54cef/attachment.html 


More information about the antlr-interest mailing list