Commit e256c17d authored by Taddeus Kroes's avatar Taddeus Kroes

funclang series4: Made lowercase out of camelcase types.

parent c81e90da
type arithOp = Plus | Minus | Times | Divide | Modulo type arith_op = Plus | Minus | Times | Divide | Modulo
type relOp = Eq | Neq | Lt | Lte | Gt | Gte type rel_op = Eq | Neq | Lt | Lte | Gt | Gte
type logicOp = And | Or type logic_op = And | Or
type binOp = ArithOp of arithOp | RelOp of relOp | LogicOp of logicOp type bin_op = ArithOp of arith_op | RelOp of rel_op | LogicOp of logic_op
type monOp = UnaryMinus | Negation type mon_op = UnaryMinus | Negation
type const = BoolConst of bool | IntConst of int type const = BoolConst of bool | IntConst of int
type expr = type expr =
Enclosure of expr Enclosure of expr
| BinOp of expr * binOp * expr | BinOp of expr * bin_op * expr
| MonOp of monOp * expr | MonOp of mon_op * expr
| Id of string | Id of string
| Const of const | Const of const
let rec eval_expr = let rec eval_expr =
let eval_binOp = let eval_bin_op =
let eval_arithOp = function let eval_arith_op = function
Plus -> "+" Plus -> "+"
| Minus -> "-" | Minus -> "-"
| Times -> "*" | Times -> "*"
| Divide -> "/" | Divide -> "/"
| Modulo -> "mod" | Modulo -> "mod"
in in
let eval_relOp = function let eval_rel_op = function
Eq -> "=" Eq -> "="
| Neq -> "!=" | Neq -> "!="
| Lt -> "<" | Lt -> "<"
...@@ -28,16 +28,16 @@ let rec eval_expr = ...@@ -28,16 +28,16 @@ let rec eval_expr =
| Gt -> ">" | Gt -> ">"
| Gte -> ">=" | Gte -> ">="
in in
let eval_logicOp = function let eval_logic_op = function
And -> "&&" And -> "&&"
| Or -> "||" | Or -> "||"
in in
function function
ArithOp op -> eval_arithOp(op) ArithOp op -> eval_arith_op(op)
| RelOp op -> eval_relOp(op) | RelOp op -> eval_rel_op(op)
| LogicOp op -> eval_logicOp(op) | LogicOp op -> eval_logic_op(op)
in in
let eval_monOp = function let eval_mon_op = function
UnaryMinus -> "-" UnaryMinus -> "-"
| Negation -> "!" | Negation -> "!"
in in
...@@ -47,25 +47,29 @@ let rec eval_expr = ...@@ -47,25 +47,29 @@ let rec eval_expr =
in in
function function
Enclosure e -> "(" ^ eval_expr(e) ^ ")" Enclosure e -> "(" ^ eval_expr(e) ^ ")"
| BinOp (e1, op, e2) -> eval_expr(e1) ^ " " ^ eval_binOp(op) | BinOp (e1, op, e2) -> eval_expr(e1) ^ " " ^ eval_bin_op(op)
^ " " ^ eval_expr(e2) ^ " " ^ eval_expr(e2)
| MonOp (op, e) -> eval_monOp(op) ^ eval_expr(e) | MonOp (op, e) -> eval_mon_op(op) ^ eval_expr(e)
| Id id -> id | Id id -> id
| Const c -> eval_const(c) | Const c -> eval_const(c)
;; ;;
(* (a) *) (* (a) *)
print_endline (eval_expr (Enclosure (Id "a")));; print_endline (eval_expr (Enclosure (Id "a")));;
(* -a *) (* -a *)
print_endline (eval_expr (MonOp (UnaryMinus, Id "a")));; print_endline (eval_expr (MonOp (UnaryMinus, Id "a")));;
(* a - b *) (* a - b *)
print_endline (eval_expr (BinOp (Id "a", ArithOp Minus, Id "b")));; print_endline (eval_expr (BinOp (Id "a", ArithOp Minus, Id "b")));;
(* a * (-b + 1) *) (* a * (-b + 1) *)
let a_times b = BinOp (Id "a", ArithOp Times, b) in let a_times b = BinOp (Id "a", ArithOp Times, b) in
let uminus a = MonOp (UnaryMinus, a) in let uminus a = MonOp (UnaryMinus, a) in
let plus a b = BinOp (a, ArithOp Plus, b) in let plus a b = BinOp (a, ArithOp Plus, b) in
let one = Const (IntConst 1) in let one = Const (IntConst 1) in
print_endline (eval_expr (a_times (Enclosure (plus (uminus (Id "b")) one))));; print_endline (eval_expr (a_times (Enclosure (plus (uminus (Id "b")) one))));;
(* a = b && c *) (* a = b && c *)
let b_and_c = BinOp (Id "b", LogicOp And, Id "c") in let b_and_c = BinOp (Id "b", LogicOp And, Id "c") in
print_endline (eval_expr (BinOp (Id "a", RelOp Eq, b_and_c)));; print_endline (eval_expr (BinOp (Id "a", RelOp Eq, b_and_c)));;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment