Next: infix notes, Previous: infix syntax, Up: infix [Contents][Index]
To determine sensible precedences for operators, we make the following observations:
and
, or
, not
, …) are meant to be applied to predicate
operand expressions and they return a boolean value.
=
, <
, >
, …) are meant to be applied to
numeric operand expressions and they return a boolean value.
+
, -
, *
, /
, …) are meant to be applied to
numeric operand expressions and they return a numeric value.
1 & 2 + ~ 3
meaning (1 & 2) + (~ 3)
, in which bitwise operators take precedence over
every other operator.
1 < i and i < 4
meaning (1 < i) and (i < 4)
,
because it makes no sense to interpret it as 1 < (i and i) < 4
.
1 + 2 < 3 + 4
meaning (1 + 2) < (3 + 4)
,
because it makes no sense to interpret it as 1 + (2 < 3) + 4
.
So MMCK Infix defines operators precedence as follows, from high precedence to low precedence:
bitwise-arithmetic-shift-left bitwise-arithmetic-shift-right fxshl fxshr
bitwise-not fxnot
bitwise-and bitwise-ior bitwise-xor fxand fxior fxxor
+ - ++ -- fx+ fx- fp+ fp-
++ -- !
expt fpexpt
quotient modulo remainder
* / fp* fp/ fx* fx/
+ - fp+ fp- fx+ fx-
< > <= >= = != fx< fx> fx<= fx>= fx= fp< fp> fp<= fp>= fp= eq? eqv? equal?
not
and or xor
… ? … : …
.
Here some expansion examples:
(infix ! 2 + 3) → (not (2 + 3)) (infix (! 2) + 3) error→ expected numeric argument (infix fxnot 3) ⇒ -4 (infix fxnot 3 + 10) ⇒ 6 (infix ! cos(3)) → (not (cos 3))
The Pratt parser allows the same operator to have different precedence when it is present in prefix
position or in postfix position. So under (mmck infix)
the following expansion takes place:
(infix ! 1 + 2) → (not (+ 1 2))
Next: infix notes, Previous: infix syntax, Up: infix [Contents][Index]
This document describes version 0.1.0-devel.0 of MMCK Infix.