-
Notifications
You must be signed in to change notification settings - Fork 0
/
imp-den-sem.ml
55 lines (42 loc) · 917 Bytes
/
imp-den-sem.ml
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
type aexp =
| Int of int
| Loc of string
| Plus of aexp * aexp
type bexp =
| T
| F
| Eq of aexp * aexp
| Not of bexp
type comm =
| Skip
| Assign of string * aexp
| Seq of comm * comm
| If of bexp * comm * comm
let rec _A aexp state = match aexp with
| Int n ->
n
| Loc l ->
state l
| Plus (a1, a2) ->
_A a1 state + _A a2 state
let rec _B bexp state = match bexp with
| T ->
true
| F ->
false
| Not b ->
not (_B b state)
| Eq (a1, a2) ->
_A a1 state = _A a2 state
let rec _C cexp state = match cexp with
| Skip ->
state
| Assign (l, a) ->
fun x -> if l=x then _A a state else state x
| Seq (c1, c2) ->
_C c2 (_C c1 state)
| If (b, c1, c2) ->
if _B b state then
_C c1 state
else
_C c2 state