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

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


You are trying to be too literal and imply context in the rules. Complement has an optional indirectObject, which is a nounPhrase, followed by an object, which is also a nounPhrase, don't use two rule to ask for the same token sequence and then make one of them an optional lead in. Use object object? And imply that the first is an indirect object if the second is present. However, parsing English isn't as easy as this of course ;-)

 

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 3:14 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Left factor? Syntactic predicates? Or another solution?

 

I am trying to write an English grammar with ANTLR and have simplified a particular problem to a particular subset for your convenience. (I'm using ANTLRWorks 1.3)

 

grammar predicate;


  
predicate : 'verb' complement?;

 

      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."

 

Is somebody easily able to left-factor this while preserving the grammar? Or syntactically predicating if better? Sorry if I sound daft! I should say that taking away the "?" from either adjectivePhrase or indirectObject does not produce this error, but they are necessary.

 

Many thanks!

N 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091001/4d95ccb5/attachment.html 


More information about the antlr-interest mailing list