File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ struct
14
14
Vihje: Abseval.eval_expr.
15
15
Vihje: Abseval.eval_guard. *)
16
16
let eval_edge (env : ED.t ) (edge : Cfg.Edge.t ): ED.t =
17
- failwith " TODO"
17
+ match edge with
18
+ | Nop -> env
19
+ | Error -> if ED. leq env ED. bot then ED. bot else failwith " eval_edge: Error"
20
+ | Assign (x , e ) -> ED. add x (eval_expr env e) env
21
+ | Guard (c , b ) -> eval_guard env c b
18
22
19
23
20
24
(* * Võrrandisüsteem juhtvoograafiga defineeritud programmi jaoks. *)
@@ -36,6 +40,16 @@ struct
36
40
Vihje: Cfg.pred.
37
41
Vihje: eval_edge. *)
38
42
let f (node : V.t ) (get : V.t -> D.t ): D.t =
39
- failwith " TODO"
43
+ let initial_env =
44
+ if V. equal node cfg.entry then
45
+ entry_env
46
+ else
47
+ D. bot
48
+ in
49
+ Cfg. pred cfg node
50
+ |> List. map (fun (edge , pred_node ) ->
51
+ eval_edge (get pred_node) edge
52
+ )
53
+ |> List. fold_left D. join initial_env
40
54
end
41
55
end
Original file line number Diff line number Diff line change 35
35
(* * Nullable võrrandite paremad pooled.
36
36
Järgi täpselt grammatikat ja ära ise lihtsusta! *)
37
37
let f (nt : V.t ) (get : V.t -> D.t ): D.t =
38
- failwith " TODO"
38
+ match nt with
39
+ | T -> get R || (false && get T && false )
40
+ | R -> true || (false && get R )
39
41
end
40
42
41
43
(* * FIRST võrrandisüsteem. *)
53
55
Vihje: D.singleton.
54
56
Vihje: D.join. *)
55
57
let f (nt : V.t ) (get : V.t -> D.t ): D.t =
56
- failwith " TODO"
58
+ match nt with
59
+ | T -> D. join (get R ) (D. singleton 'a' )
60
+ | R -> D. join D. empty (D. singleton 'b' )
57
61
end
58
62
59
63
(* * FOLLOW jaoks saaks samuti võrrandisüsteemi moodustada,
85
89
(* * Nullable võrrandite paremad pooled.
86
90
Järgi täpselt grammatikat ja ära ise lihtsusta! *)
87
91
let f (nt : V.t ) (get : V.t -> D.t ): D.t =
88
- failwith " TODO"
92
+ match nt with
93
+ | A -> (get B && get A && false ) || true
94
+ | B -> (false && get B && false ) || (get A && get A )
89
95
end
90
96
91
97
module FirstSys =
@@ -99,7 +105,9 @@ struct
99
105
Võid eeldada Nullable lahendit.
100
106
Järgi täpselt grammatikat ja ära ise lihtsusta! *)
101
107
let f (nt : V.t ) (get : V.t -> D.t ): D.t =
102
- failwith " TODO"
108
+ match nt with
109
+ | A -> D. join (D. join (get B ) (D. join (get A ) (D. singleton 'a' ))) D. empty
110
+ | B -> D. join (D. singleton 'b' ) (D. join (get A ) (get A ))
103
111
end
104
112
end
105
113
You can’t perform that action at this time.
0 commit comments