• Post Reply Bookmark Topic Watch Topic
  • New Topic

Evaluation of expression  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wanted to ask that while evaluating any expression,is the operator precedence fixed or it varies according to the compiler ,?
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's specified by the Java Language Specification.
 
radha gogia
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
YES ,agree to it ,but I am asking in general that is it the language specification or the compiler can make its own.
 
Sheriff
Posts: 4935
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
radha gogia wrote:YES ,agree to it ,but I am asking in general that is it the language specification or the compiler can make its own.


radha, this question has been answered one post above. Doesn't look that you agree
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
…but the rule that expressions are evaluated left‑to‑right must also be taken into consideration.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
radha gogia wrote:YES ,agree to it ,but I am asking in general that is it the language specification or the compiler can make its own.

A compiler is generally written to do whatever the language specification says. In Java, it is specified.

There are some famous examples in the C compiler where <something> wasn't explicitly spelled out, so each compiler was free to do stuff, within certain parameters.
 
Paul Clapham
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
radha gogia wrote:YES ,agree to it ,but I am asking in general that is it the language specification or the compiler can make its own.


Sorry, I assumed that you were asking about Java compilers. Which, as I said, are written to implement the JLS. Compiler-writers for other languages may be free to implement their own versions of that language but that (fortunately) isn't how it works in Java.
 
Campbell Ritchie
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the examples about C is this, which I tried on three different compilers once:Two of the executions printed 3 and one printed 4. That particular construct is not strictly defined in C but it is in Java®. In Java® it must print 3.
Note the official name of the language is Java® (it used to be Java™ and I am not sure when it changed). That means anybody promoting a non‑conforming compiler can get into trouble and be taken to court to prohibit the use of the trademarked name Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!