[antlr-interest] Grammar non-determinism problem

Anthony Youngman Anthony.Youngman at ECA-International.com
Thu Jun 10 08:23:28 PDT 2004


Try a "greedy = true". I've just stuffed my grammar in my bag so I can't
refer to it, but ...

decls
    : ( option {greedy=true;} : ( decl )* )
    ;

(or whatever the correct syntax is) is likely to fix it. If it doesn't,
try the same with the (typedecl)+ construct in decl. This is typical of
a * or + repeater.

Cheers,
Wol

-----Original Message-----
From: mikemoretti [mailto:antlr4 at mordent.com] 
Sent: 10 June 2004 15:53
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Grammar non-determinism problem

Hi,

I've written way too many parsers and am soooo tired of the tedious 
task of fixing grammar conflicts (especially in LL(k) parser 
tools! :D ).  In any case, I'm hoping someone can help me with this 
one (just to let you know, this isn't a homework problem, I'm working 
on a compiler for myself to learn more backend stuff since I've been 
doing mostly front end stuff for too long).

Here's a snippet of a grammar that's giving me non-determinism errors 
between end of blocks:

decls
    : ( decl )*
    ;

decl
    : (typedecl)+
    | vardecl
    | funcdecl
    ;

typedecl
    : TYPE ID ...  // don't worry about this ...
                   // it has nothing to do with the problem
    ;

vardecl
    : VAR ID TYPEID
    ;

funcdecl
    : FUNC ID ...
    ;

The non-determinism happens between decl's (typedecl)+ and decls' 
(decl)*.  I can't think of any other way to rewrite this to do what I 
need to do.  The problem is that I need to group typedecls together 
because some of them can be mutually recursive structure types (but 
only those in the same group can be, otherwise I wouldn't group them 
at all because without the + this grammar works!).  I've tried so 
many things, hoisting out stuff, hoisting + predicates, other 
rewritings that I usually try, but nothing seems to make this 
conflict go away.

Thanks!
-Mike M.





 
Yahoo! Groups Links



 



****************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 8272 5300, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

****************************************************************************



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list