add evalString to interpreter

This commit is contained in:
darkf 2013-10-19 02:21:34 -07:00
parent e8d068f10b
commit d10596f037
1 changed files with 8 additions and 0 deletions

View File

@ -113,11 +113,19 @@ apply (FnV pats) arg =
evalProgram :: [AST] -> Value -- fold the state from each node and return the result
evalProgram nodes = evalState (foldr1 (>>) $ map eval nodes) initialState
evalString :: String -> Value
evalString program =
case parseProgram program of
Left err -> error $ show err
Right prg -> evalProgram prg
main = do
print $ evalProgram prg
print $ evalProgram prg2
print $ evalProgram prg3
print $ evalProgram prg4
print $ evalString "f() -> 5+2. f()."
print $ evalString "f([x, y, z]) -> z. f([1, 2, 3])."
where
prg = [Def "x" (IntConst 5),
Def "y" (IntConst 3),