dcsimg
nondeterminism warning
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jonathan_Ringle
Posted On:   Wednesday, March 20, 2002 02:44 PM

Hello, I'm a newbie to ANTLR and I decided to examine some of the examples provided. I looked at the cpp/calc example and saw that it was an incomplete example that only provided expressions for add and mult with no parenthesis support. I figured that fleshing it out was an excersize for the reader, so I proceeded as such. What I came up with follows below. The compiled executable calc.exe works as I expect it to, but the ANTLR Parser Generator spits out the following warnings that I don't understand, nor can I find any reference to the warning in any docs provided. Thanks, ANTLR Parser Generator Version 2.7.1 1989-2000 jGuru.com calc.g:14: warning: nondeterminism upon calc.g:   More>>

Hello,

I'm a newbie to ANTLR and I decided to examine some of the examples provided. I looked at the cpp/calc example and saw that it was an incomplete example that only provided expressions for add and mult with no parenthesis support. I figured that fleshing it out was an excersize for the reader, so I proceeded as such. What I came up with follows below. The compiled executable calc.exe works as I expect it to, but the ANTLR Parser Generator spits out the following warnings that I don't understand, nor can I find any reference to the warning in any docs provided.

Thanks,



			
ANTLR Parser Generator Version 2.7.1 1989-2000 jGuru.com
calc.g:14: warning: nondeterminism upon
calc.g:14: k==1:PLUS,MINUS
calc.g:14: between alt 1 and exit branch of block
calc.g:18: warning: nondeterminism upon
calc.g:18: k==1:MULT,DIV
calc.g:18: between alt 1 and exit branch of block




------ start of calc.g -------

			
options {
language="Cpp";
}

class CalcParser extends Parser;
options {
buildAST = true; // uses CommonAST by default
}

start
: expr EQUALS!
;
expr
: mexpr ((PLUS^ | MINUS^) expr)*
;

mexpr
: atom ((MULT^ | DIV^) expr)*
| LPAREN! expr RPAREN!
;

atom
: INT
;

class CalcLexer extends Lexer;

WS_ : (' '
| ' '
| '
'
| '
')
{ _ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP; }
;

LPAREN: '('
;

RPAREN: ')'
;

MULT: '*'
;

DIV: '/'
;

PLUS: '+'
;

MINUS: '-'
;

EQUALS: '='
;

protected
DIGIT
: '0'..'9'
;

INT : (DIGIT)+
;

class CalcTreeWalker extends TreeParser;

expr returns [double r]
{
double a,b;
r=0;
}
: #(PLUS a=expr b=expr) {r = a+b;}
| #(MINUS a=expr b=expr) {r = a-b;}
| #(MULT a=expr b=expr) {r = a*b;}
| #(DIV a=expr b=expr) {r = a/b;}
| #(LPAREN a=expr) {r = a;}
| i:INT {r = atof(i->getText().c_str());}
;
   <<Less

Re: nondeterminism warning

Posted By:   Jonathan_Ringle  
Posted On:   Thursday, March 21, 2002 06:53 AM

I managed to get rid of the warning by using the following:



start
: expr EQUALS!
;
expr
: term ((PLUS^ | MINUS^) term)*
;

term
: factor ((MULT^ | DIV^) factor)*
;

factor
: atom
| LPAREN! expr RPAREN!
;

atom
: INT
;


However, I still don't quit understand what the warning meant...

About | Sitemap | Contact