File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,7 +14,15 @@ struct
1414 Vihje: Abseval.eval_expr.
1515 Vihje: Abseval.eval_guard. *)
1616 let eval_edge (env : ED.t ) (edge : Cfg.Edge.t ): ED.t =
17- failwith " TODO"
17+ match edge with
18+ | Nop -> env
19+ | Assign (x , e ) -> ED. add x (eval_expr env e) env
20+ | Error ->
21+ if ED. equal env ED. bot then
22+ ED. bot
23+ else
24+ failwith " eval_edge: Error"
25+ | Guard (c , b ) -> eval_guard env c b
1826
1927
2028 (* * Võrrandisüsteem juhtvoograafiga defineeritud programmi jaoks. *)
@@ -36,6 +44,16 @@ struct
3644 Vihje: Cfg.pred.
3745 Vihje: eval_edge. *)
3846 let f (node : V.t ) (get : V.t -> D.t ): D.t =
39- failwith " TODO"
47+ let initial_env =
48+ if V. equal node cfg.entry then
49+ entry_env
50+ else
51+ D. bot
52+ in
53+ Cfg. pred cfg node
54+ |> List. map (fun (edge , prev_node ) ->
55+ eval_edge (get prev_node) edge
56+ )
57+ |> List. fold_left D. join initial_env
4058 end
4159end
Original file line number Diff line number Diff line change 88
99(* * Näited. *)
1010
11- (* * T → R
11+ (* *T' → T$
12+ T → R
1213 T → aTc
1314 R →
1415 R → bR
3536 (* * Nullable võrrandite paremad pooled.
3637 Järgi täpselt grammatikat ja ära ise lihtsusta! *)
3738 let f (nt : V.t ) (get : V.t -> D.t ): D.t =
38- failwith " TODO"
39+ match nt with
40+ | T -> get R || (false && get T && false )
41+ | R -> true || (false && get R )
3942 end
4043
4144 (* * FIRST võrrandisüsteem. *)
5356 Vihje: D.singleton.
5457 Vihje: D.join. *)
5558 let f (nt : V.t ) (get : V.t -> D.t ): D.t =
56- failwith " TODO"
59+ match nt with
60+ | T -> D. join (get R ) (D. singleton 'a' )
61+ | R -> D. join D. empty (D. singleton 'b' )
5762 end
5863
5964 (* * FOLLOW võrrandisüsteem. *)
@@ -72,7 +77,15 @@ struct
7277 Järgi täpselt grammatikat ja ära ise lihtsusta!
7378 Vihje: join_list. *)
7479 let f (nt : V.t ) (get : V.t -> D.t ): D.t =
75- failwith " TODO"
80+ match nt with
81+ | T -> join_list [
82+ D. singleton '$' ;
83+ D. singleton 'c'
84+ ]
85+ | R -> join_list [
86+ get T ;
87+ get R
88+ ]
7689 end
7790end
7891
You can’t perform that action at this time.
0 commit comments