parse: refactored block parsing; all: added while loops

This commit is contained in:
2017-05-19 13:35:32 +02:00
parent 6a651bbf1a
commit ca11f51e33
3 changed files with 45 additions and 14 deletions

View File

@@ -18,6 +18,15 @@ eval state [(BDef (BSym sym) expr)] =
in (val, M.insert sym val newstate)
eval state [x@(BBool _)] = (x, state)
eval state [x@(BErr _)] = (x, state)
eval state [x@(BWhile cond body)] =
let (evald, whilestate) = eval state cond
in
if truthy evald
then let
(bodyval, newstate) = eval whilestate body
(val, retstate) = eval newstate [x]
in if truthy val then (val, retstate) else (bodyval, retstate)
else (BBool False, whilestate)
eval state [(BIf cond body alt)] =
let (evald, ifstate) = eval state cond
in