term1 operator1 term2 operator2 term3
operator2
has precedence over operator1,
the subexpression (term2 operator2 term3)
is evaluated first.* (multiply) has a
higher priority than + (add), so
3+2*5 evaluates to
13 (rather than
the 25 that would result if a
strict left-to-right evaluation occurred).
To force the addition to occur before the multiplication, you could rewrite
the expression as (3+2)*5.
Adding the parentheses makes the first
three tokens a subexpression. Similarly, the expression
-3**2 evaluates
to 9 (instead of
-9) because the prefix minus operator
has a higher priority than the power operator.| ~ ~~ | (message send) |
| + - ¬ \ | (prefix operators) |
| ** | (power) |
| * / % // | (multiply and divide) |
| + - | (add and subtract) |
| (blank) || (abuttal) | (concatenation with or without blank) |
| = > < | (comparison operators, all with equal precedence) |
| == >> << | |
| \= ¬= | |
| >< <> | |
| \> ¬> | |
| \< ¬< | |
| \== ¬== | |
| \>> ¬>> | |
| \<< ¬<< | |
| >= >>= | |
| <= <<= | |
| & | (and) |
| | && | (or, exclusive or) |
A is a variable
whose value is 3,
DAY is a variable whose value is
Monday, and other variables are
uninitialized. Then:
Say A+5 --> "8"
Say A-4*2 --> "-5"
Say A/2 --> "1.5"
Say 0.5**2 --> "0.25"
Say (A+1)>7 --> "0" /* that is, .false */
Say " "="" --> "1" /* that is, .true */
Say " "=="" --> "0" /* that is, .false */
Say " "\=="" --> "1" /* that is, .true */
Say (A+1)*3=12 --> "1" /* that is, .true */
Say "077">"11" --> "1" /* that is, .true */
Say "077" >> "11" --> "0" /* that is, .false */
Say "abc" >> "ab" --> "1" /* that is, .true */
Say "abc" << "abd" --> "1" /* that is, .true */
Say "ab " << "abd" --> "1" /* that is, .true */
Say Today is Day --> "TODAY IS Monday"
Say "If it is" day --> "If it is Monday"
Say Substr(Day,2,3) --> "ond" /* Substr is a function */
Say "!"xxx"!" --> "!XXX!"
-3**2 == 9 /* not -9 */
-(2+1)**2 == 9 /* not -9 */
2**2**3 == 64 /* not 256 */