[antlr-interest] Re: syn pred / lookahaed doesn't work

cintyram cintyram at yahoo.com
Tue Mar 11 11:52:56 PST 2003

--- In antlr-interest at yahoogroups.com, "Gunnar Wagenknecht"
<kreismeister at y...> wrote:
> Hi!
> I have a grammar where the syn. pred. doesn't seem to work. I can 
> post the whole grammar but the following example should be ok to 
> recognize the problem.
> compilationUnit : statementList (function)*;
> function : ("static"|"init"|"exit")? "function" identName crlf
>            statementList;
> identName : IDENTIFIER;
> statementList: (statement)*;  // <<< here I get non-determinisme 
>                               // warning upon
>                               // k=1 "static"|"exit"
>                               // k=2 
> statement: ...
>          | variableDeclaration
>          | ...
>          | "exit" crlf
>          | ...
>          ;
> variableDeclaration : ("public"|"private"|"local"|"static") identName 
> crlf;

from what you have given i assume the follwoing :
1. a compilation unit is a statement list followed by zero or more
2. a statementlist is a list of zero or more statements
3. and a statement is a variable declaration or "exit" or something
else ..

in this case it is clear that for a look ahead of 1, ie  at k=1 ,

the symbol can be "public" , "private" .. etc ..

but it is not sure which rule to use to match if the first symbol is
"exit" as it can appear in both a statement and in a function .
so the ambiguity 
similarly for "static" it can be a variable declaration of a function ..
if you use the same analysis, you will know why you are getting the
other ambiguity warnings .. 
also  i am asking out of personal suspicion did you have an alt which
means that a statement rule can match a function also?
  statement : other alts
               | function    /// do you have this in your grammar?
               | other alts 

> I tried to reslove things with syn. pred. but whatever I do I 
> couldn't remove the warning. The generated parser also doen't work 
> correct.

however i suggest that you should post the actual predicates that you
used, to know why they dont seem to work ;

ps: reading the code generated can give you a good idea of whats
happening "behind the scenes" :)
> What can I do to resolve the warning?
> Thanks, Gunnar


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

More information about the antlr-interest mailing list