Ajout de l'underscore dans le let in, et du prInt dans les let.
This commit is contained in:
parent
08ee9787f2
commit
353e83a805
@ -103,7 +103,7 @@ and eval e env = match e with
|
|||||||
| VInt k -> VInt k
|
| VInt k -> VInt k
|
||||||
| x -> raise (InvalidTypeException ("Int",x)))
|
| x -> raise (InvalidTypeException ("Int",x)))
|
||||||
| Var(v) -> readVar env v (UnknownVariableException (v,env))
|
| Var(v) -> readVar env v (UnknownVariableException (v,env))
|
||||||
| LetIn(v,e0,e1) -> eval e1 ((v,eval e0 env)::env)
|
| LetIn(v,e0,e1) -> eval e1 (let x=(eval e0 env) in if v="_" then env else (v,x)::env) (* Le let est là pour forcer l'évaluation *)
|
||||||
| App(e0,e1) -> (match (eval e0 env) with
|
| App(e0,e1) -> (match (eval e0 env) with
|
||||||
| VFunc(v,e) -> eval (LetIn(v,e1,e)) env (* On utilise l'équivalence (fun x->e) y <=> let x=y in e *)
|
| VFunc(v,e) -> eval (LetIn(v,e1,e)) env (* On utilise l'équivalence (fun x->e) y <=> let x=y in e *)
|
||||||
| x -> raise (InvalidTypeException ("Func",x)))
|
| x -> raise (InvalidTypeException ("Func",x)))
|
||||||
|
|||||||
@ -33,5 +33,5 @@ rule token = parse (* la "fonction" aussi s'appelle token .. *)
|
|||||||
| "in" { IN }
|
| "in" { IN }
|
||||||
| "fun" { FUN }
|
| "fun" { FUN }
|
||||||
| "->" { MAPSTO }
|
| "->" { MAPSTO }
|
||||||
| ['a'-'z']+ as v { VAR (v) }
|
| (['a'-'z' 'A'-'Z' '_'])(['a'-'z' 'A'-'Z' '0'-'9' '_'])* as v { VAR (v) }
|
||||||
| eof { raise Eof } (* fin du fichier *)
|
| eof { raise Eof } (* fin du fichier *)
|
||||||
|
|||||||
@ -37,14 +37,14 @@ let rec affiche_printexpr e env = begin
|
|||||||
| Band(e1,e2) -> affiche_printexpr e1 env;affiche_printexpr e2 env
|
| Band(e1,e2) -> affiche_printexpr e1 env;affiche_printexpr e2 env
|
||||||
| Bor(e1,e2) -> affiche_printexpr e1 env;affiche_printexpr e2 env
|
| Bor(e1,e2) -> affiche_printexpr e1 env;affiche_printexpr e2 env
|
||||||
| ITE(ec,e1,e2) -> affiche_printexpr ec env;affiche_printexpr e1 env;affiche_printexpr e2 env
|
| ITE(ec,e1,e2) -> affiche_printexpr ec env;affiche_printexpr e1 env;affiche_printexpr e2 env
|
||||||
| _ -> ()
|
| PrInt (e) -> (match (eval e env) with
|
||||||
end;
|
| VInt(k) -> print_int k
|
||||||
begin
|
| x -> raise (InvalidTypeException ("Int",x)));affiche_printexpr e env
|
||||||
match e with
|
| LetIn(v,e0,e) -> affiche_printexpr e0 env;affiche_printexpr e (let x=(eval e0 env) in if v="_" then env else (v,x)::env)
|
||||||
| PrInt e -> (match (eval e env) with
|
| App(e0,e1) -> affiche_printexpr e0 env;(match (eval e0 env) with
|
||||||
| VInt(k) -> print_int k;print_newline ()
|
| VFunc(v,e) -> affiche_printexpr (LetIn(v,e1,e)) env (* On utilise l'équivalence (fun x->e) y <=> let x=y in e *)
|
||||||
| x -> raise (InvalidTypeException ("Int",x)))
|
| x -> raise (InvalidTypeException ("Func",x)))
|
||||||
| _ -> ()
|
| Const(_) | BConst(_) | Fun (_,_) | Var(_) -> ()
|
||||||
end
|
end
|
||||||
(* le traitement d'une expression en entrée *)
|
(* le traitement d'une expression en entrée *)
|
||||||
let execute e =
|
let execute e =
|
||||||
|
|||||||
1
Rendu0/tests/func.ml
Normal file
1
Rendu0/tests/func.ml
Normal file
@ -0,0 +1 @@
|
|||||||
|
(fun x -> fun y -> fun x -> x+y*2) 0 19 4
|
||||||
Loading…
x
Reference in New Issue
Block a user