From: Roedy Green on
On Mon, 25 Jan 2010 14:00:36 +0100, "Robbo" <nie.mam(a)yle.com> wrote,
quoted or indirectly quoted someone who said :

>There is no information about "new" which is also operator:

new does behave like an ordinary operator with precedence. It must be
immediately followed by a ClassName. It cannot occur in any other
context. I guess one way of looking at this is new has extremely high
precedence. It is in my table.


see http://mindprod.com/jgloss/precedence.html

My table also has some notes on each operator, MORE button links to a
detailed discussion of each operator, and examples of use. My table
is aimed at newbies, not language lawyers (compiler implementors).

I still need to write something on == and !=, and the += family.

--
Roedy Green Canadian Mind Products
http://mindprod.com
Don�t be discouraged by a failure. It can be a positive experience. Failure is, in a sense, the highway to success, inasmuch as every discovery of what is false leads us to seek earnestly after what is true, and every fresh experience points out some form of error which we shall afterwards carefully avoid.
~ John Keats (born: 1795-10-31 died: 1821-02-23 at age: 25)
From: Robbo on
> see http://mindprod.com/jgloss/precedence.html

Your table is good piece of work. Much better than many
incomplete tutorials which may be found all over the internet.

But, if I am right, a few hours ago there was no information
about "new". Probably you have added it not more than
a few hours ago.
Where did you find information that "new" is officially
operator in Java? I am really interested in this topic.
Patricia Shanahan (in this thread) has said that "new" is not an operator.
I have not found any information that would confirm
that "new" is an operator in JLS (3rd edition).

And the second thing. In your table there is (cast) operator
at precedence of 1 (it has the same priority as prefix and unary
operators). Also association is "Right".
If I am right (byte)++x means that ++ is computed before (byte)
-- both (cast) and prefix ++ have the same priority and association
is "Right".
And in (byte)x++, (byte) is first because of higher priority of cast
than postfix ++.
What do you think?

Robbo


From: Mike Schilling on
Robbo wrote:
>> see http://mindprod.com/jgloss/precedence.html
>
> Your table is good piece of work. Much better than many
> incomplete tutorials which may be found all over the internet.
>
> But, if I am right, a few hours ago there was no information
> about "new". Probably you have added it not more than
> a few hours ago.
> Where did you find information that "new" is officially
> operator in Java? I am really interested in this topic.
> Patricia Shanahan (in this thread) has said that "new" is not an
> operator. I have not found any information that would confirm
> that "new" is an operator in JLS (3rd edition).

"Operator" means different things to different people. A parser guy
would probably call "new" an operator; because it combines expressions
into a more complex expression and has a defined precedence. But the
"offical" list of operators is found at
http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.12
and doesn't include cast, new, or parentheses.

> And the second thing. In your table there is (cast) operator
> at precedence of 1 (it has the same priority as prefix and unary
> operators). Also association is "Right".
> If I am right (byte)++x means that ++ is computed before (byte)
> -- both (cast) and prefix ++ have the same priority and association
> is "Right".
> And in (byte)x++, (byte) is first because of higher priority of
> cast
> than postfix ++.
> What do you think?

Other way around. Postfix ++ has a higher precedence than the cast
does.


From: Robbo on
> Other way around. Postfix ++ has a higher precedence than the cast
> does.

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.

I really wish official table of Java operators with precedence
and associations.
In C++ situations is not better. E.g. 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.

Robbo


From: Lew on
Robbo wrote:
>> Your table is good piece of work. Much better than many
>> incomplete tutorials which may be found all over the internet.
>>
>> But, if I am right, a few hours ago there was no information
>> about "new". Probably you have added it not more than
>> a few hours ago.
>> Where did you find information that "new" is officially
>> operator in Java? I am really interested in this topic.
>

It is not. The keyword 'new' is officially not an operator in Java.

> > Patricia Shanahan (in this thread) has said that "new" is not an
> > operator. I have not found any information that would confirm
> > that "new" is an operator in JLS (3rd edition).
>

That's because 'new' is not an operator in the JLS (any edition), ergo
in the Java language.

As Patricia also pointed out, the JLS defines the language, therefore
there is no higher authority.

Mike Schilling wrote:
> "Operator" means different things to different people.  A parser guy
> would probably call "new" an operator; because it combines expressions
> into a more complex expression and has a defined precedence. But the
> "offical" list of operators is found at
> <http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.12>
>

This link has been posted before in this thread. OP: you should read
it.

> and doesn't include cast, new, or parentheses.
>

nor "dot". However, the JLS does refer to 'instanceof' as an
operator.

This question has now been answered several times in this thread. You
might want to consider accepting the answer.

Robbo wrote:
>> And the second thing. In your table there is (cast) operator
>> at precedence of 1 (it has the same priority as prefix and unary
>> operators). Also association is "Right".

Don't you mean "associativity"?

>> If I am right (byte)++x means that ++ is computed before (byte)
>> -- both (cast) and prefix ++ have the same priority and association [sic]
>> is "Right".
>> And in (byte)x++,  (byte) is first because of higher priority of
>> cast than postfix ++.
>> What do you think?
>

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.
Both cast and postfix operators are right-associative, therefore the
postfix operator is evaluated first.

The precedence is indicated by the order in which the operators and
other expressions (e.g., cast expressions) appear in chapter 15 of the
JLS.
<http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html>

and is defined by the productions in
<http://java.sun.com/docs/books/jls/third_edition/html/
syntax.html#18.1>

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