exception TypeError
exception UndefinedVar
exception DivByZeroError
Copyright By PowCoder代写 加微信 powcoder
(* Remove shadowed bindings *)
let prune_env (env : environment) : environment =
let binds = List.sort_uniq compare (List.map (fun (id, _) -> id) env) in
List.map (fun e -> (e, List.assoc e env)) binds
(* Env print function to stdout *)
let print_env_std (env : environment): unit =
List.fold_left (fun _ (var, value) ->
match value with
| Int_Val i -> Printf.printf “- %s => %s\n” var (string_of_int i)
| Bool_Val b -> Printf.printf “- %s => %s\n” var (string_of_bool b)
| Closure _ -> ()) () (prune_env env)
(* Env print function to string *)
let print_env_str (env : environment): string =
List.fold_left (fun acc (var, value) ->
match value with
| Int_Val i -> acc ^ (Printf.sprintf “- %s => %s\n” var (string_of_int i))
| Bool_Val b -> acc ^ (Printf.sprintf “- %s => %s\n” var (string_of_bool b))
| Closure _ -> acc
) “” (prune_env env)
(***********************)
(****** Your Code ******)
(***********************)
(* evaluate an arithmetic expression in an environment *)
let rec eval_expr (e : exp) (env : environment) : value =
(* evaluate a command in an environment *)
let rec eval_command (c : com) (env : environment) : environment =
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com