Skip to content

Commit

Permalink
simplify eval.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed May 24, 2010
1 parent a487b85 commit ddcb943
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions Eval.hs
Expand Up @@ -12,22 +12,18 @@ evaluate exp0 = eval exp0 empty

eval :: Exp -> Stack Exp -> Exp
eval (exp1 :. exp2) stack = eval exp1 $ push exp2 stack
eval exp1 stack = exec stack exp1

exec :: Stack Exp -> Exp -> Exp
exec stack0 exp1
| isEmpty stack0 = exp1
exec stack0 exp1@(Var _) = foldl (:.) exp1 $ map evaluate stack0
exec stack0 S = eval (x :. z :. (y :. z)) stack3
eval exp1 stack
| isEmpty stack = exp1
eval exp1@(Var _) stack = foldl (:.) exp1 $ map evaluate stack
eval S stack = eval (x :. z :. (y :. z)) stack3
where
(x,stack1) = pop stack0
(x,stack1) = pop stack
(y,stack2) = pop stack1
(z,stack3) = pop stack2
exec stack0 K = eval x stack2
eval K stack = eval x stack2
where
(x,stack1) = pop stack0
(x,stack1) = pop stack
(_,stack2) = pop stack1
exec stack0 exp0@(_ :. _) = eval exp0 stack0

----------------------------------------------------------------

0 comments on commit ddcb943

Please sign in to comment.