Skip to content
Snippets Groups Projects
Commit 644e8fda authored by pm3g19's avatar pm3g19
Browse files

Tweaked outline and added evalFull

parent ec10778b
No related branches found
No related tags found
No related merge requests found
...@@ -2,21 +2,21 @@ module Eval where ...@@ -2,21 +2,21 @@ module Eval where
import Types import Types
import Debug import Debug
eval :: Environment -> Expr -> Expr --only focus on one expression eval, evalFull :: Environment -> Expr -> Expr --only focus on one expression
findVar :: Environment -> SymbolName -> Expr findVar :: Environment -> SymbolName -> Expr
findVar = notImplemented findVar = notImplemented
addVar :: Environment -> SymbolName -> Expr -> Environment addVar :: Environment -> SymbolName -> Expr -> Environment
addVar = notImplemented addVar = notImplemented
eval env expr = let eval' = eval env in case expr of -- evaluates expression to weak-head normal form (i.e. top level data structure is not a FuncCall) eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr of -- evaluates expression to weak-head normal form (i.e. top level data structure is not a FuncCall)
FuncCall func inputSets args -> case func of FuncCall func inputSets args -> case func of
(PredefFunc f) -> case f of (PredefFunc f) -> case f of
(Filter) -> let (Set inputRecords,predicate) = (eval' $ head inputSets, eval' $ head args) in (Filter) -> let (Set inputRecords,predicate) = (eval' $ head inputSets, eval' $ head args) in
Set $ filter ((==Boolean True).eval')(map (\r -> FuncCall predicate [] [r]) inputRecords) -- result is weak-head normal form Set $ filter ((==Boolean True).eval')(map (\r -> FuncCall predicate [] [r]) inputRecords) -- result is weak-head normal form
--Set $ map (eval env) (map (\r -> FuncCall predicate [] [r]) inputRecords) # don't evaluate last step --Set $ map (eval env) (map (\r -> FuncCall predicate [] [r]) inputRecords) # don't evaluate last step
(IsEqual) -> let (e1:e2:_) = args in (IsEqual) -> let (e1:e2:_) = args in -- TODO not sufficent.
Boolean (eval' e1 == eval' e2) Boolean (evalFull' e1 == evalFull' e2)
(RecordIndex) -> let (Record recordData, Int index) = (eval' $ args !! 0, eval' $ args !! 1) in (RecordIndex) -> let (Record recordData, Int index) = (eval' $ args !! 0, eval' $ args !! 1) in
recordData !! index recordData !! index
...@@ -25,7 +25,7 @@ eval env expr = let eval' = eval env in case expr of -- evaluates expression to ...@@ -25,7 +25,7 @@ eval env expr = let eval' = eval env in case expr of -- evaluates expression to
--(Map) -> Set $ (map (\r -> FuncCall predicate [] [r]) inputRecords) --(Map) -> Set $ (map (\r -> FuncCall predicate [] [r]) inputRecords)
(FuncDef setParams argParams body) -> eval newEnv body (FuncDef setParams argParams body) -> eval newEnv body
where where
newEnv = notImplemented newEnv = let (setEnv, argsEnv) = (zip setParams inputSets, zip argParams args) in setEnv ++ argsEnv ++ env
--newEnv = foldl (\env entry@(name, expr) -> addVar env name expr) env --adds entries to environment --newEnv = foldl (\env entry@(name, expr) -> addVar env name expr) env --adds entries to environment
-- TODO FIX -- TODO FIX
(Var name) -> findVar env name (Var name) -> findVar env name
...@@ -36,3 +36,6 @@ eval env expr = let eval' = eval env in case expr of -- evaluates expression to ...@@ -36,3 +36,6 @@ eval env expr = let eval' = eval env in case expr of -- evaluates expression to
evalControl1 :: Environment -> Expr -> Expr evalControl1 :: Environment -> Expr -> Expr
evalControl1 env (Control _ (currentExpr:exprs)) = let output = eval env currentExpr in Control output exprs evalControl1 env (Control _ (currentExpr:exprs)) = let output = eval env currentExpr in Control output exprs
evalFull = eval -- evaluates expression fully (not just weak head normal form)
--TODO implement properly
\ No newline at end of file
import Types import Types
import Debug import Debug
import Eval import Eval
import System.IO
parse :: String -> Program parse :: String -> Program
parse = notImplemented parse = notImplemented
--outline --outline
interpret :: String -> IO () -- the main function, takes in source code, prints out result interpret :: FilePath -> IO () -- the main function, takes in file name, prints out result
interpret source = do interpret sourceFName = do
source <- readFile sourceFName
let program = parse source -- main abstract syntax tree let program = parse source -- main abstract syntax tree
(env, mainExpr) <- prepare program (env, mainExpr) <- prepare program
let output = eval env mainExpr let output = eval env mainExpr
...@@ -22,22 +24,16 @@ prepare (inputSets,instructions) = do ...@@ -22,22 +24,16 @@ prepare (inputSets,instructions) = do
let mainExpr = Control (head csvData) instructions let mainExpr = Control (head csvData) instructions
return (env, mainExpr) return (env, mainExpr)
where loadInputFiles = mapM loadInputFile where
loadInputFiles = mapM loadInputFile
evalFinal :: Expr -> Expr -- whnf set to ready set evalFinal :: Expr -> Expr -- whnf set to ready set
evalFinal = notImplemented evalFinal = evalFull []
showFinal :: Expr -> IO () showFinal :: Expr -> IO ()
showFinal = notImplemented showFinal = notImplemented
---eval :: Control -> Expr -- fully evaluates the program, returning a set
zipM (a,b) = do
a' <- a
b' <- b
return (a',b')
--pairmap f s = (s, fs)
-------------------------------------------- --------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment