From b080ea7c810a0c649582215a4ab4f18beb1eaf55 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 8 Aug 2015 18:23:49 -0700 Subject: [PATCH] Add if-statement evaluation --- src/evaluate.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/evaluate.rs b/src/evaluate.rs index caaf8b7..acaae4b 100644 --- a/src/evaluate.rs +++ b/src/evaluate.rs @@ -55,12 +55,25 @@ fn reduce(evr: EvalResult) -> EvalResult { match ast { + IfStatement(if_clause, then_clause, else_clause) => { + let (condition, new_env) = reduce((*if_clause, env)); + match condition { + Null => match else_clause { + Some(cl) => reduce((*cl, new_env)), + None => (DoNothing, new_env) + }, + + _ => reduce((*then_clause, new_env)) + } + }, + BinOp(op, lhs, rhs) => { let (reduced_lhs, new_env) = reduce((*lhs, env)); let (reduced_rhs, new_env2) = reduce((*rhs, new_env)); let result: AST = reduce_binop(*op, reduced_lhs, reduced_rhs); (result, new_env2) }, + Name(name) => { let result = match env.lookup_binding(&name) { Some(binding) => match binding {