-
which operator binds tighter? Is
1 + 2 * 3
parsed as
1 + (2 * 3)
or(1 + 2) * 3
? If precedences are different, associativity does not come into play. -
prefix vs. infix -- assuming
=
is right-associative, and!
is as well, since prefix operators seem to have to associate to the right, consider:! x = 3
Is that
!(x = 3)
or(!x) = 3
?
Only matters when precedences are equal.
-
left vs. right:
1 + 2 + 3
parsed as1 + (2 + 3)
or(1 + 2) + 3
? -
non-associativity:
1 @@ 2 @@ 3
where@@
is a non-associative operator: parse error -
mixed associativity, same precedence:
x = 3 + 1
or2 + 3 = x
, assuming that+
and=
have the same precedence but opposite associativities. Probably should result in parse error. -
prefix vs. postfix
! x ++
Is it
(!x) ++
or!(x++)
? (Probably the latter -- but I guess it should be resolved by precedences)
-
prefix vs. infix: what does each use of
-
mean?3 - - - -- q
-
prefix vs. postfix: what does each use of
++
mean?++ x + ++ y * z ++
-
associativity of prefix operators: right-only (???)
! ! ! ! x
-
precedence of prefix vs. postfix: irrelevant, since can't do both on same operand (???) i.e. can't do:
++ x ++
-
associativity of postfix operators: none, b/c only one allowed? i.e. can't do
x ++ ++
Counterpoint: C and C++ might support multiple postfix operators.
-
low-precedence postfix: parse this:
3 + x ++ * 5
as
((3 + x) ++) * 5
, assuming++
is lower precedence than+
?(3 + x) ++
doesn't make sense- I haven't found any low-precedence postfix operators in practice
- would the
++
really interfere with*
?
- unsolved: how to parse the ternary
? :
operator
-
mixed associativity, same precedence
infixr @@ 5 infixl $$ 5 prefix ! 5 postfix # 5 x @@ y $$ z -- error x $$ y @@ z -- error ! x @@ y -- error x $$ y # -- error
-
postfix operator in non-postfix context
++
-
non-postfix operator in postfix context
-
non-prefix operator in prefix context (can this be reliably recognized?)
-
missing operand
x + a * b ^