This commit is contained in:
Mylloon 2023-12-15 19:27:03 +01:00
parent 814c04c1d0
commit 34c2a6c8e3
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -122,7 +122,8 @@ let free_variables =
in
(* Une variable libre est une variable qui peut être substitué *)
(* TODO : rajouter des explications pour While Define et Fun *)
(* 1.2
TODO : rajouter des explications pour While Define et Fun *)
let rec fvs = function
| S.Literal _ -> M.empty
| S.Variable x -> M.singleton x
@ -205,6 +206,8 @@ let translate (p : S.t) env =
let fs, defs = define_recursive_functions fdefs in
fs @ List.map (fun (x, e) -> T.DefineValue (x, e)) defs
and define_recursive_functions rdefs =
(* 1.5
TODO *)
failwith "Students! This is your job (define_recursive_functions)!"
and expression env = function
| S.Literal l -> [], T.Literal (literal l)
@ -220,6 +223,7 @@ let translate (p : S.t) env =
in
[], xc
| S.Define (vdef, a) ->
(* 1.3 (2) *)
let afs, a = expression env a in
(match vdef with
| S.SimpleValue (id, b) ->
@ -227,8 +231,11 @@ let translate (p : S.t) env =
afs @ bfs, T.Define (identifier id, a, b)
| S.RecFunctions _ -> failwith "Students! This is your job (S.RecFunctions)!")
| S.Apply (a, bs) ->
(* 1.3 (4) *)
let afs, a = expression env a in
let bsfs, bs = expressions env bs in
(* 1.4
TODO *)
afs @ bsfs, T.UnknownFunCall (a, bs)
| S.IfThenElse (a, b, c) ->
let afs, a = expression env a in
@ -236,6 +243,8 @@ let translate (p : S.t) env =
let cfs, c = expression env c in
afs @ bfs @ cfs, T.IfThenElse (a, b, c)
| S.Fun (x, e) as f ->
(* 1.3 (3)
TODO: J'ai une boucle infini ici je comprends rien *)
let fname = make_fresh_function_identifier () in
let x = List.map identifier x in
let efs, e = expression env e in