EXPRESSIONS
Prefix Increment Operator
++
15.14.1
of a unary
+
 operating on
q
, or a binary addition of two quantities
p
 and
q
. In C
and C++, the parser handles this problem by performing a limited amount of
semantic analysis as it parses, so that it knows whether
p
 is the name of a type or
the name of a variable.
Java takes a different approach. The result of the
+
 operator must be numeric,
and all type names involved in casts on numeric values are known keywords.
Thus, if
p
 is a keyword naming a primitive type, then
(p)+q
 can make sense only
as a cast of a unary expression. However, if
p
 is not a keyword naming a primitive
type, then
(p)+q
 can make sense only as a binary arithmetic operation. Similar
remarks apply to the
 operator. The grammar shown above splits
CastExpression
into two cases to make this distinction. The nonterminal
UnaryExpression
includes all unary operator, but the nonterminal
UnaryExpressionNotPlusMinus
excludes uses of all unary operators that could also be binary operators, which in
Java are
+
 and
.
The second potential ambiguity is that the expression
(p)++
 could, to a C or
C++ programmer, appear to be either a postfix increment of a parenthesized
expression or the beginning of a cast, for example, in
(p)++q
. As before, parsers
for C and C++ know whether
p
 is the name of a type or the name of a variable. But
a parser using only one token lookahead and no semantic analysis during the
parse would not be able to tell, when
++
 is the lookahead token, whether
(p)
should be considered a
Primary
 expression or left alone for later consideration as
part of a
CastExpression
.
In Java, the result of the
++
 operator must be numeric, and all type names
involved in casts on numeric values are known keywords. Thus, if
p
 is a keyword
naming a primitive type, then
(p)++
 can make sense only as a cast of a prefix
increment expression, and there had better be an operand such as
q
 following the
++
. However, if
p
 is not a keyword naming a primitive type, then
(p)++
 can make
sense only as a postfix increment of
p
. Similar remarks apply to the
  
 operator.
The nonterminal
UnaryExpressionNotPlusMinus
 therefore also excludes uses of
the prefix operators
++
 and
  
.
15.14.1   Prefix Increment Operator
++
A unary expression preceded by a
++
 operator is a prefix increment expression.
The result of the unary expression must be a variable of a numeric type, or a com 
pile time error occurs. The type of the prefix increment expression is the type of
the variable. The result of the prefix increment expression is not a variable, but a
value.
At run time, if evaluation of the operand expression completes abruptly, then
the prefix increment expression completes abruptly for the same reason and no
incrementation occurs. Otherwise, the value
1
 is added to the value of the variable
347






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved