exception TypeError
exception UndefinedVar
exception DivByZeroError
Copyright By Assignmentchef assignmentchef
(* 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
var (string_of_int i)
| Bool_Val b -> Printf.printf – %s => %s
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
var (string_of_int i))
| Bool_Val b -> acc ^ (Printf.sprintf – %s => %s
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: assignmentchef QQ: 1823890830 Email: [email protected]
Reviews
There are no reviews yet.