[antlr-interest] Understanding nondeterminism warnings: and howtodebug them

PATERSON, Robert r.paterson at ioof.com.au
Thu Feb 23 13:49:37 PST 2006


Actually I just realised that replacing compoundStatement with
statementSequence won't give you the grammar you're after. Perhaps just
making simpleStatement non-optional will do the trick... 

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of PATERSON, Robert
Sent: Friday, 24 February 2006 8:47 AM
To: Vladimir Sutskever
Cc: antlr-interest at antlr.org
Subject: RE: [antlr-interest] Understanding nondeterminism warnings: and
howtodebug them

Let me preface these comments with "I'm an ANTLR newbie with an
imperfect mental map of what ANTLR does", but that said, I think it's
complaining because your compoundStatement can contain a compound
statements or empty simple statements.

So it's thinking goes something like this:

program: PROGRAM ID SEMI_COLON ->
compoundStatement: BEGIN 
    and then either (simpleStatement/*completely optional so can be
empty*/ SEMI simpleStatement /*completely optional so can be empty*/)
    or
    compountStatement: BEGIN
;


So it gets to BEGIN and says to itself, "Well it looks like it's
complete valid to follow the BEGIN with another BEGIN or with a
completely empty simpleStatement followed by a SEMI colon..."

Anyway, that's my guess at it.

I'd say if you replaced:

program: PROGRAM ID SEMI_COLON (typeDefinitions)?
(variableDeclarations)? (subprogramDeclarations)? compoundStatement;

With something like:

program: PROGRAM ID SEMI_COLON (typeDefinitions)?
(variableDeclarations)? (subprogramDeclarations)? statementSequence;


And:

simpleStatement : ( (assignmentStatement | procedureStatement) )?;

With

simpleStatement : (assignmentStatement | procedureStatement);



A lot of your problems will go away.



-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Vladimir
Sutskever
Sent: Friday, 24 February 2006 6:17 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Understanding nondeterminism warnings: and how
todebug them

I cant seem to get rid of the few nondeterminism warnings that appear
when I attempt to generate the parser.
How would I debug something like this? Line #14 does not have "BEGIN" 
...how do the warning line #'s correspond to my grammar?
This is my first attempt to generate some grammar, and I know I lack
much(all) of the intuition behind it.

Hopefully you guys/gals can help me get trough this :) I have attached
my grammar file.
This is the error nondeterminism error I get:

grammer.txt:14:75: warning:nondeterminism between alts 1 and 2 of block
upon
grammer.txt:14:75:     k==1:BEGIN
grammer.txt:40: warning:nondeterminism upon
grammer.txt:40:     k==1:SEMI_COLON
grammer.txt:40:     between alt 1 and exit branch of block
grammer.txt:58:21: warning:nondeterminism between alts 1 and 2 of block
upon
grammer.txt:58:21:     k==1:ID
grammer.txt:69:56: warning:nondeterminism between alts 1 and 2 of block
upon
grammer.txt:69:56:     k==1:ELSE
grammer.txt:105: warning:nondeterminism between alts 3 and 4 of block
upon
grammer.txt:105:     k==1:ID

-Vladimir



************************************************************************
****
IMPORTANT - PLEASE READ
This communication is intended only for the use of the addressee and 
may contain personal information, confidential information or legally 
privileged information. If personal information is contained in this
e-mail, 
then it is governed by the Privacy Act 1988 and must be treated in 
accordance with the Privacy Act 1988 by the recipient. The legal 
privilege and confidentiality attached to this e-mail is not waivered, 
lost or destroyed by reason of mistaken delivery to you. If you are not 
the intended recipient, we would appreciate immediate notification by 
return e-mail or telephoning +61-3-8614-4444 and ask that the message 
be permanently deleted from your system. If you are the intended 
recipient of this communication you should not copy, disclose or
distribute this communication without the authority of IOOF or its
related entities (the IOOF Group).
Any views expressed in this message are those of the individual sender, 
except where they are specifically stated to be the views of the IOOF 
Group.
This e-mail and any attachments have been scanned for computer viruses 
using anti-viral software, but you should also perform your own scan. We

do not accept liability for any loss or damage, whether caused by our
own negligence or not, that results from a computer virus or a defect in
the transmission of the e-mail or any attached file.
************************************************************************
****



More information about the antlr-interest mailing list