CS计算机代考程序代写 open Types

open Types
open Format

let string_of_const =
function True -> “true”
| False ->”false”
| Int n -> string_of_int n
let string_of_op =
function
Plus -> “(+)”
| Minus -> “(-)”
| Times -> “(*)”
| Div -> “(/)”
| Lt -> “(<)" | Gt -> “(>)”
| Le -> “(<=)" | Ge -> “(>=)”
| Eq -> “(=)”
| And -> “(&&)”
| Or -> “(||)”

let rec fprint_val f =
function Const c -> fprintf f “%s” (string_of_const c)
| Fun (x, e) -> fprintf f “@[fun %s ->@ %a@]” x fprint_exp e
| Op o -> fprintf f “%s” (string_of_op o)
and fprint_exp f =
function Var v -> fprintf f “%s” v
| Value v -> fprint_val f v
| Let (x, e1, e2) ->
fprintf f “@[let %s =@ %a@ in@ @[%a@]@]”
x
fprint_exp e1
fprint_exp e2
| If (e1, e2, e3) ->
fprintf f “@[if@ %a@ then@ %a@ else@ %a@]”
fprint_exp e1
fprint_exp e2
fprint_exp e3
| App (e1, e2) ->
fprintf f “@[app@ %a@ to@ %a@]”
fprint_exp e1
fprint_exp e2
let pprint_exp e =
(fprint_exp Format.std_formatter e;
Format.print_newline ())

Leave a Reply

Your email address will not be published. Required fields are marked *