Antoine Pietri avatar Antoine Pietri committed 677a81e

added Makefile, begginned eval.ml

Comments (0)

Files changed (3)

 _build
 *.byte
 *.native
+*.swp
+NAME := blaise
+
+all:
+	ocamlbuild -Is . ${NAME}.native
+
+clean:
+	ocamlbuild -clean
+let int_of_bool b = if b then 1 else 0
+
+and bool_of_int n = if n = 0 then 0 else 1
+
+and hashtbl_set env = raise false
+
+and rec eval_expr env lf = function
+  | Ast.Int(n) -> n
+  | Ast.Var(v) -> Hashtbl.find env v
+  | Ast.BinOp(e1, op, e2) ->
+      eval_binop op (eval_expr env lf e1) (eval_expr env lf e2)
+  | Ast.UniOp(op, e) -> eval_uniop op (eval_expr env lf e)
+  | Ast.Call(f, exprl) -> eval_func f (eval_list_expr env lf exprl)
+
+and rec eval_list_expr env lf = List.map (function x -> eval_expr env lf x)
+
+and eval_binop op i1 i2 = match op with
+  | "+"     -> i1 + i2
+  | "-"     -> i1 - i2
+  | "*"     -> i1 * i2
+  | "/"     -> i1 / i2
+  | ">"     -> int_of_bool (i1 > i2)
+  | "<"     -> int_of_bool (i1 < i2)
+  | "<="    -> int_of_bool (i1 <= i2)
+  | ">="    -> int_of_bool (i1 >= i2)
+  | "=="    -> int_of_bool (i1 == i2)
+  | "||"    -> int_of_bool ((bool_of_int i1) || (bool_of_int i2))
+  | "&&"    -> int_of_bool ((bool_of_int i1) && (bool_of_int i2))
+  | op      -> failwith ("Unknown operator " ^^ op)
+
+and eval_uniop op i = match op with
+  | "!" -> int_of_bool (not bool_of_int (i))
+  | op  -> failwith ("Unknown operator " ^^ op)
+
+and eval_statement env lf = function
+  | Ast.Assign(v, e) -> Hashtbl.
+
+and eval_func f lf args =
+  raise false
+
+and eval_statement_list env lf =
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.