Skip to content

Commit 848fa8b

Browse files
committed
Lahenda constraint praktikumis
1 parent dcaaab3 commit 848fa8b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/constraint/abseval/constraint_abseval.ml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ 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+
| 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
1822

1923

2024
(** Võrrandisüsteem juhtvoograafiga defineeritud programmi jaoks. *)
@@ -36,6 +40,16 @@ struct
3640
Vihje: Cfg.pred.
3741
Vihje: eval_edge. *)
3842
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
4054
end
4155
end

src/constraint/grammar/constraint_grammar.ml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ struct
3535
(** Nullable võrrandite paremad pooled.
3636
Järgi täpselt grammatikat ja ära ise lihtsusta! *)
3737
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)
3941
end
4042

4143
(** FIRST võrrandisüsteem. *)
@@ -53,7 +55,9 @@ struct
5355
Vihje: D.singleton.
5456
Vihje: D.join. *)
5557
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')
5761
end
5862

5963
(** FOLLOW jaoks saaks samuti võrrandisüsteemi moodustada,
@@ -85,7 +89,9 @@ struct
8589
(** Nullable võrrandite paremad pooled.
8690
Järgi täpselt grammatikat ja ära ise lihtsusta! *)
8791
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)
8995
end
9096

9197
module FirstSys =
@@ -99,7 +105,9 @@ struct
99105
Võid eeldada Nullable lahendit.
100106
Järgi täpselt grammatikat ja ära ise lihtsusta! *)
101107
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))
103111
end
104112
end
105113

0 commit comments

Comments
 (0)