mirror of
https://github.com/LucasVbr/postscript-compiler.git
synced 2026-05-13 17:22:00 +00:00
Update typing.ml
Add find_var that search var in environment
This commit is contained in:
+29
-4
@@ -3,11 +3,36 @@
|
|||||||
open Lang
|
open Lang
|
||||||
|
|
||||||
(* Environments *)
|
(* Environments *)
|
||||||
|
type environment = {
|
||||||
type environment =
|
localvars: (vname * tp) list;
|
||||||
{localvars: (vname * tp) list;
|
|
||||||
funbind: fundecl 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
|
let tp_prog (Prog (fundecls, fundefns)) = true
|
||||||
Reference in New Issue
Block a user