Affichage des expressions
This commit is contained in:
parent
e2e80bf55c
commit
8ba594ee3d
23
affichage.ml
23
affichage.ml
@ -1,21 +1,14 @@
|
||||
open Expr
|
||||
|
||||
(* fonction d'affichage *)
|
||||
let rec affiche_expr e =
|
||||
let aff_aux s a b =
|
||||
begin
|
||||
print_string s;
|
||||
affiche_expr a;
|
||||
print_string ", ";
|
||||
affiche_expr b;
|
||||
print_string ")"
|
||||
end
|
||||
in
|
||||
match e with
|
||||
| Const k -> print_int k
|
||||
| Add(e1,e2) -> aff_aux "Add(" e1 e2
|
||||
| Mul(e1,e2) -> aff_aux "Mul(" e1 e2
|
||||
| Min(e1,e2) -> aff_aux "Min(" e1 e2
|
||||
let rec string_of_expr = function
|
||||
Fun ((s, t), e) -> "fun ("^s^":"^t^") => "^(string_of_expr e)
|
||||
| App (e1, e2) -> "("^(string_of_expr e1)^") "^(string_of_expr e2)
|
||||
| Var (s) -> s
|
||||
| Exf (e, s) -> "exf("^(string_of_expr e)^":"^s^")"
|
||||
|
||||
let print_expr e =
|
||||
print_string (string_of_expr e)
|
||||
|
||||
let affiche_val v = print_string "TODO"
|
||||
|
||||
|
@ -20,7 +20,7 @@ rule token = parse
|
||||
| '0' { BOTTOM }
|
||||
| '(' { LPAREN }
|
||||
| ')' { RPAREN }
|
||||
| "FUN" { FUN }
|
||||
| "fun" { FUN }
|
||||
| ':' { COLON }
|
||||
| "=>" { ARR }
|
||||
| "exf" { EXFALSO }
|
||||
|
5
main.ml
5
main.ml
@ -1,10 +1,11 @@
|
||||
open Expr
|
||||
open Affichage
|
||||
|
||||
let interpret e =
|
||||
begin
|
||||
affiche_expr e;
|
||||
print_expr e;
|
||||
print_newline();
|
||||
print_int (eval e);
|
||||
(*print_int (eval e);*)
|
||||
print_newline()
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user