PROPOSAL: open and close brace optional for single statement try, catch, finally, method declaration
Tom Hawtin
Thomas.Hawtin at Sun.COM
Mon Mar 30 06:25:01 PDT 2009
Glenn A. Marshall wrote:
> 1. This example is syntactically invalid since the first try does not have
> a catch nor finally clause; it is not ambiguous. Good example tho.
Neal's example:
>> try
>> try stmt;
>> catch(...) stmt;
>> catch(...) stmt;
>> finally stmt;
Under the proposal "try stmt; catch(...) stmt;" is a statement. So the
above is equivalent to:
try
stmt2;
catch(...) stmt;
finally stmt;
But "try stmt; catch(...) stmt; catch(...) stmt;" is also a statement.
So the example is also equivalent to:
try
stmt2;
finally stmt;
Which is different. Which is it?
This is similar to the dangling-else ambiguity.
http://en.wikipedia.org/wiki/Dangling_else
> 2. The optional omission of the braces is only applicable to simple, single
> statement try, catch, finally (and method declaration). Braces are still
> allowed, and are required for disambiguation, as well as for multiple
> statement try, catch finally (and method declaration). They are are needed
> in this example.
That reads as if you think of a block statement (in for example the
typical while usage) as not a type of statement. A block is a statement.
You could ammend the grammar so the proposal uses non-block statement,
but this is not how the rest of the language works.
BTW: Does anyone have a good suggestion for tool and basic Java grammar
to check that syntax modifications are still parseable?
Tom
More information about the coin-dev
mailing list