Content deleted Content added
More tidying up and better examples. |
No edit summary |
||
Line 8:
Each operator is given a position, precedence, and an associativity. The '''operator precedence''' is a number (from high to low or vice versa) that defines which operator that takes an operand surrounded by two operators of different precedence (or priority). Multiplication normally has higher precedence than addition, for example, so 3+4×5 = 3+(4×5) ≠ (3+4)×5.
In terms of operator position, an operator may be prefix, postfix, or infix. A prefix operator immediately precedes its operand, as in −x. A postfix operator immediately succeeds its operand, as in x! for instance. An infix operator is positioned in between a left and a right operand, as in
'''[[Operator associativity]]''', determines what happens when an operand is surrounded by operators of the same precedence
Unary prefix operators such as − (negation) or sin (trigonometric function) are typically associative prefix operators
Mathematically oriented languages (such as on [[scientific calculator]]s) often allow implicit multiplication with higher priority than prefix operators (such as sin). Therefore, sin 2x+1 = (sin(2x))+1, for instance, just as in mathematics.
Line 23:
# For equal precedence, bind operands to operators according to the associativity of the operators.
Some more examples:
4 + -x + 3 = (4 + (-x)) + 3
==Generalizations of Common Operator Notation==
|