Update typing.ml

Add find_var that search var in environment
This commit is contained in:
Lucàs
2023-03-18 22:56:04 +01:00
parent 26eb53c358
commit 88361f0579
+28 -3
View File
@@ -3,11 +3,36 @@
open Lang
(* Environments *)
type environment =
{localvars: (vname * tp) list;
type environment = {
localvars: (vname * tp) list;
funbind: fundecl list
}
let find_var (var: vname) (env: environment) =
let rec aux local_vars =
match local_vars with
| [] -> failwith "Variable inconnue"
| tete::reste ->
let (name, _) = tete in
if name = var
then tete
else aux reste
in aux (env.localvars)
;;
(* let rec tp_expr (expression: expr) (env: environment) =
match expression with
| Const(const) ->
match const with
| BoolV(_) -> BoolT
| FloatV(_) -> FloatT
| IntV(_) -> IntT
| LitV(_) -> LitT
| StringV(_) -> StringT
| VarE(var) -> tp_expr (find_var var env) env
| BinOp(op, expr1, expr2) ->
| CondE(expr1, expr2, expr3) ->
| CallE(functionName, exprList) -> *)
;;
let tp_prog (Prog (fundecls, fundefns)) = true