From: Lew on
Robbo wrote:
> It means there is mistake in Mr. Doedy Green's table
> (http://mindprod.com/jgloss/precedence.html).
> In this table prefix and postfix has the same priority -- probably
> simple mistake with numbers of precedence.
> But more serious mistake in his table is that prefix is before
> postfix. According to
> <http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html>
> postfix goes first.
>

Roedy has prefix/unary at the same level of precedence as postfix, not
at a higher level. Still a difference, but one that makes no
difference since right-associativity would still have postfix
operators evaluated first.

> I really wish official table of Java operators with precedence
> and associations.

You just cited an official table. Didn't that grant your wish?
<<http://java.sun.com/docs/books/tutorial/java/nutsandbolts/
operators.html>
(copied and pasted from your post)

Why are you asking for something you already have?

> In C++ situations is not better. E.g. [sic] here
> <http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B>
> there is information that postfix has precedence 2 and prefix has
> precedence 3. In my Polish edition of Stroustrup's book
> postfix and prefix has the same precedence.
>

That's off topic, but let me suggest that those differences may be due
to changes in the language, perhaps. Not that I really know.

--
Lew
From: Robbo on
After reading a few resources, I created such table:

Level Category Operator Associativity
---------------------------------------------------------------
1 postfix expr++ expr-- left
---------------------------------------------------------------
2 prefix ++expr --expr right
unary +expr -expr right
logical NOT ! right

bitwise NOT ~ left
---------------------------------------------------------------
3 cast (type) right
---------------------------------------------------------------
4 multiplicative * / % left
---------------------------------------------------------------
5 additive + - left
---------------------------------------------------------------
6 shift << >> >>> left
---------------------------------------------------------------
7 relational < <= > >= left
type comparison instanceof
---------------------------------------------------------------
8 equality == != left
---------------------------------------------------------------
9 bitwise AND & left
---------------------------------------------------------------
10 bitwise XOR ^ left
---------------------------------------------------------------
11 bitwise OR | left
---------------------------------------------------------------
12 logical AND && left
---------------------------------------------------------------
13 logical OR || left
---------------------------------------------------------------
14 conditional ?: right
---------------------------------------------------------------
15 assignment = += -= *= /= right
%= &= ^= |=
<<= >>= >>>=
---------------------------------------------------------------

What do you think about this?
It contains only real Java operators, I hope.

I have a few problems with this table:
1. According to some resources, postfix and prefix
have the same level (precedence). It is right?
2. How about associativity of ~ ?
3. How about level (precedence) of "cast"?
Shouldn't it be in level 2?



From: Mike Schilling on
Lew wrote:
> Mike Schilling wrote:
>> Other way around. Postfix ++ has a higher precedence than the cast
>> does.
>
> I believe the issue here is one of associativity, not precedence.

No, it really is precedence. You can't sensibly define associatively
among a group of unary operators that include both left-hand and
right-hand operators. That's why the two postfix operators (++ and --)
are at a precedence level all their own, while the corresponding
prefix operators share a level with casts.

> Both cast and postfix operators are right-associative, therefore the
> postfix operator is evaluated first.

Postfix operators aren't associative at all, since you can't use two
of them, e.g.. i++++ is iilegal.


From: znôrt on
On Mon, 25 Jan 2010 23:20:23 +0100, Robbo <nie.mam(a)yle.com> wrote:

> What do you think about this?

that you ...

a). are working on yet another compiler/parser/whatever or
b). have way too much time and too little to do :-)

bytheway, parenthesis do a great job making abritrarily complex
expressions evident to anyone reading any code. they have the (great)
added benefit of being language independent and widely recognised. just
use them! (if you really are in need for such complex expressions).
From: Mike Schilling on
Lew wrote:

> However, the JLS does refer to 'instanceof' as an
> operator.

But it's not in the list of operators, so the JLS contradicts itself.
It really is the Java programmer's Bible!

More seriously, the official JLS definition of "operator" describes
only operators made up of special characters; that is, it
distinguishes "operator" from "keyword". If "new" were spelled "^" as
in

InputStream strm = ^FileInputStream(filename);

the JLS would presumably call it an operator. If you think of
operator as a semantic term rather than a syntactical one, you're
likely to define it to include "instanceof" and "new".


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: ?k???O?T?h???C
Next: JVM and java application