Skip to content
Snippets Groups Projects
Commit 6b24abe8 authored by Cesar Roux Dit Buisson's avatar Cesar Roux Dit Buisson
Browse files

Rename calc example to use run as entry point

Remebered ctx creation also needs to be added after each function entry, so .log.js versions not currently working with interpreter example.
parent 0d943f22
No related branches found
No related tags found
No related merge requests found
......@@ -11,13 +11,13 @@ and sexpr =
| Emp [@f]
| Push [@f value, stack] of expr * sexpr
let rec eval_ expr = match expr with
let rec run expr = match expr with
| Const n -> n
| Add (ls, rs) -> eval_ ls + eval_ rs
| Sub (ls, rs) -> eval_ ls - eval_ rs
| Mul (ls, rs) -> eval_ ls * eval_ rs
| Div (ls, rs) -> eval_ ls / eval_ rs
| Add (ls, rs) -> run ls + run rs
| Sub (ls, rs) -> run ls - run rs
| Mul (ls, rs) -> run ls * run rs
| Div (ls, rs) -> run ls / run rs
| Pop s -> Stack.pop (evals s)
and evals sexpr = match sexpr with
| Emp -> Stack.N
| Push (v, s) -> Stack.push (eval_ v) (evals s)
| Push (v, s) -> Stack.push (run v) (evals s)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment