-
Notifications
You must be signed in to change notification settings - Fork 1
/
treeops.sml
61 lines (55 loc) · 1.48 KB
/
treeops.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(* treeops.sml
*
* Arithmetic and relational operations used in trees.
*
* Copyright (c) 2005 by Matthias Blume ([email protected])
*)
structure TreeOps = struct
datatype binop =
PLUS | MINUS | MUL | DIV | MOD
| AND | OR | LSHIFT | RSHIFT | ARSHIFT | XOR
datatype relop =
EQ | NE | LT | GT | LE | GE
| ULT | ULE | UGT | UGE
fun binop2string PLUS = "+"
| binop2string MINUS = "-"
| binop2string MUL = "*"
| binop2string DIV = "/"
| binop2string MOD = "%"
| binop2string AND = "&"
| binop2string OR = "|"
| binop2string LSHIFT = "<<"
| binop2string RSHIFT = ">>"
| binop2string ARSHIFT = "~>>"
| binop2string XOR = "^"
fun relop2string EQ = "=="
| relop2string NE = "<>"
| relop2string LT = "<"
| relop2string GT = ">"
| relop2string LE = "<="
| relop2string GE = ">="
| relop2string ULT = "!<"
| relop2string UGT = "!>"
| relop2string ULE = "!<="
| relop2string UGE = "!>="
fun notRel EQ = NE
| notRel NE = EQ
| notRel LT = GE
| notRel GE = LT
| notRel LE = GT
| notRel GT = LE
| notRel ULT = UGE
| notRel UGE = ULT
| notRel ULE = UGT
| notRel UGT = ULE
fun commute EQ = EQ
| commute NE = NE
| commute LT = GT
| commute GT = LT
| commute LE = GE
| commute GE = LE
| commute ULT = UGT
| commute UGT = ULE
| commute ULE = UGE
| commute UGE = ULE
end