PROPOSAL: open and close brace optional for single statement try, catch, finally, method declaration

Tom Hawtin Thomas.Hawtin at Sun.COM
Mon Mar 30 09:28:29 PDT 2009

Neal Gafter wrote:
> On Mon, Mar 30, 2009 at 8:07 AM, Tom Hawtin <Thomas.Hawtin at> wrote:

>> I think that is inappropriately pedantic. JLS 3rd Ed, 14.5/p368: 'the if
>> statement of the Java programming language suffers from the so-called
>> "dangling else problme,".' I don't know how parser implementations tend to
>> handle the issue.
> Parser implementations tend to handle the issue by following the
> grammar in the JLS, which is not ambiguous.  See the discussion
> following your quote.

A reason why I wasn't sure is that there are two Java grammars in the 
JLS. The (non-normative, IIRC) Chapter 18/p585 states:

    "The grammar presented piecemeal in the preceding chapters is much 
better for exposition, but it is not well suited as a basis for a 
parser. The grammar presented in this chapter is the basis for the 
reference implementation."

The grammer contains:

         if ParExpression Statement [else Statement]

I believe that causes an ambiguity.

Are the quoted statements dated, wrong or something else?

Tom Hawtin

More information about the coin-dev mailing list