grammatica-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Grammatica-users] Lookahead feature?


From: Thomas Moschny
Subject: [Grammatica-users] Lookahead feature?
Date: Fri, 2 Sep 2005 16:54:43 +0200
User-agent: KMail/1.8.2

Hi!

while working on a grammar, I am struggling with this sort of productions:

Goal = A | B ;
A    = a+ b ;
B    = a+ c ;

It is clear that this grammar is not LL(k), and thus grammatica tells me that 
there is an inherent ambiguity in production 'Goal'. The normal way to deal 
with this problem would be to do left-factoring, I think:

Goal  = a+ (ATail|BTail) ;
ATail = b;
BTail = c;

But, this is ugly, isn't it? In fact, there is no ambiguity in the original 
grammar. Imho, the left-factoring makes the grammar bigger and less readable. 
Maybe not in this example, but there are more complicated cases.

It would be nice, if one could give grammatica a hint that it's ok to search 
for the right production in such cases  - some sort of marker or something 
similar to the LOOKAHEAD(..) feature of JavaCC:

Goal = lookahead(A) A | B ;
(If A would match, use the first subrule, don't bother with the second.)

Any thoughts or comments on this?

Regards,
Thomas

Attachment: pgp14EYu5EYQC.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]