Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Re: Looking for good table with all Java operators (http://www.velocityreviews.com/forums/t712809-re-looking-for-good-table-with-all-java-operators.html)

John B. Matthews 01-25-2010 02:45 AM

Re: Looking for good table with all Java operators
 
In article <hjioae$jef$1@atlantis.news.neostrada.pl>,
"Robbo" <nie.mam@yle.com> wrote:

> Hello,
>
> I need to create complete table of Java operators
> with their priorities and associations. In Sun's web
> page there is such table but not complete (e.g. there
> are no operators like (), .), there is only one sentence
> about associations. I tried to create such a table
> myself, but do not know if it is correct. Please,
> check my table or provide me with some good
> link where I may find good table.
>
> Thx.
>
> Kategoria Operator £±czno¶æ
> ??? () [] . Left to right
> Postfix expr++ epxr-- Right to left
> Unary ++expr --expr Right to left
> +expr -expr ! ~
> Multiplicative * / % Left to right
> Additive + - Left to right
> Shift >> >>> << Left to right
> Relational > >= < <= Left to right
> instanceof
> Equality == != Left to right
> Bitwise AND & Left to right
> Bitwise XOR ^ Left to right
> Bitwise OR | Left to right
> Logical AND && Left to right
> Logical OR || Left to right
> Conditional ?: Right to left
> Assignment = += -= *= Right to left
> /= %= >>=
> <<= >>>= &=
> ^= |=
> Comma , Left to right


Sun:
<http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html>

Princeton:
<http://www.cs.princeton.edu/introcs/11precedence/>

University of West Florida:
<http://www.cs.uwf.edu/~eelsheik/cop2253/resources/op_precedence.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Lew 01-25-2010 03:36 AM

Re: Looking for good table with all Java operators
 
Robbo wrote:
>> I need to create complete table of Java operators
>> with their priorities and associations. In Sun's web
>> page there is such table but not complete (e.g. there
>> are no operators like (), .), there is only one sentence


Those aren't operators.
<http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.11>
<http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.12>

>> about associations. I tried to create such a table


Do you mean "associativity"?

John B. Matthews wrote:
> Sun:
> <http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html>
>
> Princeton:
> <http://www.cs.princeton.edu/introcs/11precedence/>
>
> University of West Florida:
> <http://www.cs.uwf.edu/~eelsheik/cop2253/resources/op_precedence.html>


They're pretty darn easy to find.
<http://www.google.com/search?q=java+operator+precedence+table>
(The UWF link is top on the list, the Sun link is second, the Princeton link
fourth.)

--
Lew

Lew 01-25-2010 03:01 PM

Re: Looking for good table with all Java operators
 
Robbo wrote:
>> Those aren't operators.


Please attribute citations.

> If not, why tables of operators you provided me with include () [] and . ?
>
> Look:
>
>>> Princeton:
>>> <http://www.cs.princeton.edu/introcs/11precedence/>
>>>
>>> University of West Florida:
>>> <http://www.cs.uwf.edu/~eelsheik/cop2253/resources/op_precedence.html>


People's interpretations are not normative. The JLS defines the terms that
apply to Java.

Did you even read the definitions in the JLS to which I linked?

--
Lew

Roedy Green 01-25-2010 03:17 PM

Re: Looking for good table with all Java operators
 
On Mon, 25 Jan 2010 13:22:09 +0100, "Robbo" <nie.mam@yle.com> wrote,
quoted or indirectly quoted someone who said :

>
>If not, why tables of operators you provided me with include () [] and . ?


You could describe Java with a grammar that considered them as
operators with a precedence. They do fit into the precedence scheme
even if they don't usually cause any sort of calculation. (cast) does
sometime do a sort of computation.

--
Roedy Green Canadian Mind Products
http://mindprod.com
Dont 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)

Joshua Cranmer 01-25-2010 04:25 PM

Re: Looking for good table with all Java operators
 
On 01/25/2010 10:46 AM, Robbo wrote:
> Thanks for the answer. Well, this
> http://java.sun.com/docs/books/tutor...operators.html
> seems to be complete table of operators in Java. The only problem
> I see is lack of "cast operator".


Java calls it a "cast expression"; if you carefully read the JLS, you'll
notice it is at the same level of precedence as an unary operator.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Roedy Green 01-25-2010 04:51 PM

Re: Looking for good table with all Java operators
 
On Mon, 25 Jan 2010 14:00:36 +0100, "Robbo" <nie.mam@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
Dont 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)

Mike Schilling 01-25-2010 08:55 PM

Re: Looking for good table with all Java operators
 
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/t...ical.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.



Lew 01-25-2010 10:06 PM

Re: Looking for good table with all Java operators
 
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

Lew 01-25-2010 10:13 PM

Re: Looking for good table with all Java operators
 
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/tutor.../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

Mike Schilling 01-25-2010 10:20 PM

Re: Looking for good table with all Java operators
 
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.




All times are GMT. The time now is 03:24 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.