Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Operator Precedence Mnemonic.

 
Anthony Roy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is designed to not only tell you the precedence of the operations, but also how many operators at each level (count the letters in each word of the mnemonic). Well, it helped me :-):
Leave On Undies About Sad Couples Bed So TAntalizingly.
Language(5): . (method/instance invocation)
() (Parameters to a method)
[] (Array index)
-- ++ Pre inc/dec
Object(2): (cast), new
Unary(6): +,-,!,~,++,-- (post inc/dec)
Arithmetic(5): *,/,%,+,-
Shift(3): >>, >>>, <<
Comparison(7): <,>,<=,>=,==,!=, instanceof
Bitwise(3): &, ^, |
Shortcut(2): &&, ||
Ternary(1): ? :
Assignment(12): =, +=, -=, *=, %=, /=,
&=, ^=, |=, >>=, >>>=, <<=
 
Doug Dunn
Author
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really do not want to come off harsh, but this is an admixture of primary expressions, separators, and operators. Precedence really only applies to operators (of which there are exactly 40 in the Java programming language). Primary expressions such a method invocation and class instance creation expressions are always evaluated first. The brackets in an array index expression as well as the parentheses in a method invocation or class instance creation expression are separators, not operators. The fact that the index expression in an array creation expression is evaluated first is simply an order of evaluation question in that particular primary expression. The same is true of parameter lists. The keyword new is also not an operator, nor can it be separated from the fact that it is part of a primary expression. The use of parentheses around an operator expression makes it a primary expression that must be evaluated first, as are all primary expressions (in a left-to-right order). Besides that, mnemonics that are hard to remember are counter productive.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic