Precedence and Associativity
Next: Constant Expressions
Up: Expressions
Previous: & and
When an expression is not fully parenthesized, the proper nesting of
subexpressions may in principle be ambiguous. The following precedence and
associativity rules are used to resolve such ambiguity; the table
lists the higher-precedence operators before lower-precedence ones:
. [ ] ( )
~ - (unary minus)
**
// * /
|| + - (binary minus)
< <= = ~= >= >
&
|
The binary operators are all left associative, except for the
exponentiation operator "**"; the exponentiation operator is
right associative. I.e.,
"a+b+c" is parsed as "(a+b)+c";
"a**b**c" is parsed as "a**(b**c)";
"a[10].b" is parsed as "(a[10]).b";
"a.b[10]" is parsed as "(a.b)[10]".
theta-questions@lcs.mit.edu