[antlr-interest] Grammar non-determinism problem

mikemoretti antlr4 at mordent.com
Thu Jun 10 07:52:32 PDT 2004


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

<*> 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