début pattern
This commit is contained in:
parent
67434aab60
commit
d149e5d1e7
1 changed files with 24 additions and 6 deletions
|
@ -541,11 +541,14 @@ and apply_expression f x environment memory =
|
||||||
| VPrimitive (_, f) ->
|
| VPrimitive (_, f) ->
|
||||||
(* Fonction "primitive" *)
|
(* Fonction "primitive" *)
|
||||||
f memory x_val
|
f memory x_val
|
||||||
| VClosure (_env_fn, _pattern, _expr) ->
|
| VClosure (_env_fn, _pattern, _expr) ->(*
|
||||||
(*
|
|
||||||
let pattern _env_fn (value pattern) x_val with
|
let pat = pattern _env_fn (value pattern) x_val in (*Pattern va nous calculer un nouvelle environnement*)
|
||||||
|
match pat with
|
||||||
|
| Some(env') -> expression' env' memory expression
|
||||||
|
| None -> failwith ("erreur")*)
|
||||||
(* Fonction
|
(* Fonction
|
||||||
* TODO: Pattern matching ici *)*)
|
* TODO: Pattern matching ici *)
|
||||||
failwith "Students! This is your job (Apply)!"
|
failwith "Students! This is your job (Apply)!"
|
||||||
| _ -> assert false (* By typing *)
|
| _ -> assert false (* By typing *)
|
||||||
|
|
||||||
|
@ -554,14 +557,29 @@ and literal_expression = function
|
||||||
| LChar c -> VChar c
|
| LChar c -> VChar c
|
||||||
| LString s -> VString s
|
| LString s -> VString s
|
||||||
|
|
||||||
|
|
||||||
|
(*TODO : à la place des TODO, mettre des autres fonctions pour calculer chaque cas*)
|
||||||
|
|
||||||
(*
|
(*
|
||||||
and pattern environment pattern expression =
|
and pattern environment pattern expression =
|
||||||
match pattern, expression with
|
match pattern, expression with
|
||||||
| PLiteral pl, _ -> literal_pattern pl
|
| PLiteral pl, _ -> literal_pattern pl
|
||||||
| PWildcard, _ -> environment
|
| PWildcard, _ -> environment
|
||||||
| PTypeAnnotation(new_pattern,_), _ -> pattern environment new_pattern expression
|
| PVariable var,_ -> Environment.bind environment var.value expression
|
||||||
|
| PTypeAnnotation(new_pattern,_), _ -> pattern (environment new_pattern expression)
|
||||||
|
| PTaggedValue(cons,_,new_pattern),_ -> (*Erreur ?*)failwith "erreur"
|
||||||
|
| PTaggedValue(cons,_,new_pattern),VTagged(cons2,new_pattern2) -> (* TODO *)failwith "erreur"
|
||||||
|
| PRecord(r,_), _ -> (* Erreur ?*) failwith "erreur"
|
||||||
|
| PRecord(r,_),VRecord(r2) -> (*TODO*)failwith "erreur"
|
||||||
|
| PTuple(tab),_ -> (* Erreur ?*)failwith "erreur"
|
||||||
|
| PTuple(tab),VTuple(tab2) -> (*TODO*)failwith "erreur"
|
||||||
|
(* TODO POr et PAnd en vrai j'ai une idée mais la fatigue me rattrape
|
||||||
|
Je l'écris si jamais quelqu'un d'autre à part moi lis ceci
|
||||||
|
L'idée est de regarde pour POr si dans la liste de pattern, il y a au moins un élément qui match expression
|
||||||
|
PAreil pour And donc mais tout dois match*)
|
||||||
|
|
||||||
and litteral_pattern pl =
|
|
||||||
|
and literal_pattern pl =
|
||||||
match pl with
|
match pl with
|
||||||
| LInt n -> VInt n
|
| LInt n -> VInt n
|
||||||
| LChar c -> VChar c
|
| LChar c -> VChar c
|
||||||
|
|
Reference in a new issue