[antlr-interest] Nondeterminism between alts 1 and 2 of block...

Thiago F.G. Albuquerque tfga at terra.com.br
Sun May 18 09:31:52 PDT 2003


Hi, everybody,

I am facing a problem with a grammar. I was wondering if you could help me.

Here it is:

class MyParser extends Parser;

options
{
    k = 2;
}

// ---------------------------------------------------------------------------

exp : func_call         // <-- this is line 185 (the line of the error)
     | atom
     ;

func_call : ID "(" (exp ("," exp)*)? ")"
           ;

atom : variable
      | "(" exp ")"
      ;

// ---------------------------------------------------------------------------

variable : ID                  // atomic variable
          | ID ("[" exp "]")+   // array
          | ID "." variable     // struct
          ;

// ----------------------------------------------------------------------------

Error:

ANTLR Parser Generator   Version 2.7.2   1989-2003 jGuru.com
test.g:185: warning:nondeterminism between alts 1 and 2 of block upon
test.g:185:     k==1:ID
test.g:185:     k==2:"("

I don't understand how can there be nondeterminism here. func_call really 
begins with

ID "("

but it is not possible to generate this sequence of tokens from atom.

Also, I noticed that if I colapse the rules exp and atom into one rule, 
like this:

exp : func_call         // <-- this is line 185 (the line of the error)
       | variable
       | "(" exp ")"
       ;

the problem disapears.

I am puzzled.

Can anybody please explain this to me?

TIA,
Thiago


 

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




More information about the antlr-interest mailing list