Skip to content

Commit

Permalink
[mmzk] (feat) 2015 Part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
MMZK1526 committed Oct 8, 2023
1 parent 9a20980 commit dcde9b1
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Year2015/Exam.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ eval (Cond cond e e') defs st = case eval cond defs st of
eval (FunApp f exps) defs st = eval e defs st'
where
(as, e) = lookUp f defs
st' = getLocals st
++ bindArgs as (evalArgs exps defs st)
++ getGlobals st
st' = bindArgs as (evalArgs exps defs st) ++ st

---------------------------------------------------------------------
-- Part III
Expand All @@ -131,13 +129,26 @@ executeStatement :: Statement -> [FunDef] -> [ProcDef] -> State -> State
-- Pre: All statements are well formed
-- Pre: For array element assignment (AssignA) the array variable is in scope,
-- i.e. it has a binding in the given state
executeStatement
= undefined
executeStatement stmt fDefs pDefs st = case stmt of
Assign v e -> updateVar (v, eval e fDefs st) st
AssignA v i e -> updateVar (v, assignArray (getValue v st) (eval i fDefs st) (eval e fDefs st)) st
If e b1 b2 -> case eval e fDefs st of
I 0 -> executeBlock b2 fDefs pDefs st
_ -> executeBlock b1 fDefs pDefs st
While e b -> case eval e fDefs st of
I 0 -> st
_ -> executeStatement stmt fDefs pDefs (executeBlock b fDefs pDefs st)
Call v p exps -> let (as, b) = lookUp p pDefs
st' = executeBlock b fDefs pDefs (bindArgs as (evalArgs exps fDefs st) ++ st)
in case v of
"" -> st'
_ -> updateVar (v, getValue "$res" st') st'
Return exp -> updateVar ("$res", eval exp fDefs st) st

executeBlock :: Block -> [FunDef] -> [ProcDef] -> State -> State
-- Pre: All code blocks and associated statements are well formed
executeBlock
= undefined
executeBlock [] _ _ st = st
executeBlock (stmt : stmts) fDefs pDefs st = executeBlock stmts fDefs pDefs (executeStatement stmt fDefs pDefs st)

---------------------------------------------------------------------
-- Part IV
Expand Down

0 comments on commit dcde9b1

Please sign in to comment.