Affichage des expressions

This commit is contained in:
augustin64 2024-04-09 11:30:52 +02:00
parent e2e80bf55c
commit 8ba594ee3d
4 changed files with 12 additions and 18 deletions

View File

@ -1,21 +1,14 @@
open Expr open Expr
(* fonction d'affichage *) (* fonction d'affichage *)
let rec affiche_expr e = let rec string_of_expr = function
let aff_aux s a b = Fun ((s, t), e) -> "fun ("^s^":"^t^") => "^(string_of_expr e)
begin | App (e1, e2) -> "("^(string_of_expr e1)^") "^(string_of_expr e2)
print_string s; | Var (s) -> s
affiche_expr a; | Exf (e, s) -> "exf("^(string_of_expr e)^":"^s^")"
print_string ", ";
affiche_expr b; let print_expr e =
print_string ")" print_string (string_of_expr e)
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 affiche_val v = print_string "TODO" let affiche_val v = print_string "TODO"

View File

@ -20,7 +20,7 @@ rule token = parse
| '0' { BOTTOM } | '0' { BOTTOM }
| '(' { LPAREN } | '(' { LPAREN }
| ')' { RPAREN } | ')' { RPAREN }
| "FUN" { FUN } | "fun" { FUN }
| ':' { COLON } | ':' { COLON }
| "=>" { ARR } | "=>" { ARR }
| "exf" { EXFALSO } | "exf" { EXFALSO }

View File

@ -1,10 +1,11 @@
open Expr open Expr
open Affichage
let interpret e = let interpret e =
begin begin
affiche_expr e; print_expr e;
print_newline(); print_newline();
print_int (eval e); (*print_int (eval e);*)
print_newline() print_newline()
end end