>The grammar in the appendix of JLS2 indeed has problems. The ambiguity>you showed in your message is an example, and there are other issues. If>someone is interested I can post the bug reports I sent to Sun about>this.

To follow up on my own post (sorry), here is the bug report I sent Sun
about the JLS2 grammar appendix. I suspect I haven't spotted all bugs in
this grammar...

-------------------------

Dear Sir,

I have found a number errors in the Java Language Specification 2nd
edition. In particular, I found a number of significant problems in
chapter 18 (Syntax).

I have not been able to find any errata for JLS2 on your website; if
I've missed something I would be very interested to know.

This is the list of errors I've found:

* Page 193, 3rd rule of the grammar of ExplicitConstructorInvocation

Both the '.' and the keyword 'super' are terminals of the grammar,
and should be set in typewriter font (and separated with spaces).

There are other places where a similar problem occurs.

* Chapter 18, introduction.

It is implied that the syntax presented in this chapter is more suited
to be used in a parser. As a writer of a Java compiler, I have to
disagree with this. Apart from the errors (see below), the grammar
is unsuitable for use in a parser that does more than just accept
correct Java, and reject incorrect Java. For example, the production
IdentifierSuffix lumps together language constructs that a compiler
would want to keep separate. There are many examples of this.

Also, it is confusing that this chapter changes the notation for
optional occurences and lists of occurences.

* Page 450, grammar rules for Expression1 and Expression1Rest

Both rules make the part "'?' Expression ':' Expression1"
optional, which introduces a (trivial) ambiguity.

Also, why not absorb the rule for Expression1Rest in the rule
for Expression1? It is clearer and compacter.

* Page 450, grammar rule for Expression2Rest

The second production is incorrect, the term `Expression3' should be
deleted.

Again, why not absorb the grammar rule in the Expression2 rule?

* Page 450-451, grammar rule for Infixop

The precedence and binding rules for these operators are not specified,
making expressions such as 1+2*3 and 1-2-3 ambiguous.

* Page 451, grammar rule for Expression3, second production

The nonterminal 'Expr' is not defined. Surely this should be
'Expression'?