[antlr-interest] Non-determinism (again :-(

Anthony W Youngman Anthony.Youngman at ECA-International.com
Mon Apr 7 00:40:15 PDT 2003


Okay. Let's take "if then else" syntax. The assorted variants can be

IF A EQ B THEN
   C = 3
   D = 4
END ELSE
   E = 5
   F = 6
END

or

IF A EQ B THEN C = 3; D = 4 ELSE E = 5; F = 6
 or

IF A EQ B
   THEN C = 3; D = 4
   ELSE E = 5; F = 6

(or other assorted variants...)

This then goes through my parser rules (note that I haven't got round to
sorting out assigns as in my example, but the grammar won't "Tool"
without the warnings...)

statement : ( inputst | printst | exitst | ifst | loopst | "NULL" ) ;
statement_line : (statement ( SEMI! statement)* ) ;
statement_list : ( (statement_line (EOL!)+ )+ ) ;

If you look at the output from that, both statement_line and
statement_list just give you a degenerate tree consisting of a list of
statements. That's why my treeparser was presumably blowing up. If you
look back to my original post, the treeparser rules were

statement_line : ( ( statement)+ ) ; 
statement_list : ( (statement_line )+ ) ; 

Which blew up with the non-determinism warning...Rob's post gave me the
hint I needed - eliminate one of the treeparser rules and the warning
goes away. Now that I'm working on creating a virtual root for
statement_list, that's an alternative way of making the non-determinism
go away (and may prove to be the only route to a working grammar), but
my example above is certainly an exception to "one parser rule to one
treeparser rule" - the parser was doing exactly what I expected/wanted
and the treeparser was ambiguous.

Cheers,
Wol

-----Original Message-----
From: mzukowski at yci.com [mailto:mzukowski at yci.com] 
Sent: 04 April 2003 17:31
To: antlr-interest at yahoogroups.com
Subject: RE: [antlr-interest] Non-determinism (again :-(


> This is a counter-example! The problem is that both SEMI and EOL are
end-of-statement 
> markers, but they can (sometimes, not always) modify the preceding
control
structure as 
> well.

Can you show some examples?  Both rules and example code to parse.

Monty

 

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


 

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

-------------- next part --------------
This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.


More information about the antlr-interest mailing list