compound_expression: `{' top_expression_list `}' ;
A compound_expression
is a sequence of top expressions. The type and value of the
compound_expression
is the type and value of the last expression it
contains. The value to be returned from a method is not the value of
its method_body
compound. A separate return_expression
exists
to assign the method return value (see section Jumps and returns).
top_expression_list: top_expression [`;' top_expression_list] ;
Note that the semicolon is a separator, not a terminator.
top_expression: local_var_decl | expression ;
A local_var_decl
(see section Local variables) is not an
expression
because that is unnecessary:
int a = 1
can equally well be used without the
int a =
if the a
is not used anywhere else, or, it can be
braced: { int a = 1 }
. If it is used somewhere else,
the declaration can be put in the enclosing compound and then,
obviously, the plain assignment a = 1
can be used as an
expression.
int a = 1, b = a + 1
, the expression {
int a = 1; a + 1}
can be used with exactly the same semantics.
Remarks from the previous item are also valid for this case.
local_var_decl
be a normal
expression
is because it would make typing a tuple
unclear. For example, if int a = 1, b = 2
were an
expression
, the type of the tuple
(q = 1, 2, int a = 3, b = 4, 5)would depend on rules concerning the precedence of the comma in
tuple
and local_var_decl
, i.e. the precedence of the comma
would depend on its context. Since this is not considered a good idea
and because of the limited usefulness of the local_var_decl
being
an expression
(as shown in the preceding paragraphs), the
local_var_decl
is not an expression
.
Go to the first, previous, next, last section, table of contents.