Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Commit d4b0e894 authored by pm3g19's avatar pm3g19
Browse files

Added support for cartesian product

parent 492e7639
patryk,malinowski
maram, jones
jeffrey,sylvester
jian,shi
andrew,sogokon
julian,rathke
\ No newline at end of file
......@@ -17,13 +17,16 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
FuncCall func inputSets args -> case func of
(PredefFunc f) -> case f of
Filter -> let (Set inputRecords,predicate) = (eval' $ head inputSets, eval' $ head args) in
Set $ filter ((==Boolean True).(\r -> eval' $ FuncCall predicate [] [r])) $ map eval' inputRecords
Set $ filter ((==Boolean True).(\r -> eval' $ FuncCall predicate [] [r])) $ map eval' inputRecords
IsEqual -> let (e1:e2:_) = args in -- TODO not sufficent.
Boolean (eval' e1 == eval' e2)
Boolean (eval' e1 == eval' e2)
RecordIndex -> let (Record recordData:Int index:_) = (map eval' args) in
recordData !! index
recordData !! index
XProduct -> debug (show env) $ let ((Set l1): (Set l2):_) = map eval' inputSets in
Set $ [ x `concatRecord` y | x <- l1, y <- l2]
--implement later
--(Map) -> Set $ (map (\r -> FuncCall predicate [] [r]) inputRecords)
......@@ -48,4 +51,5 @@ evalControl1 env (Control last (currentExpr:exprs)) = let output = eval env curr
evalFull = eval
--evalFull env (Set xs) = Set (map (eval env) xs) -- evaluates expression fully (not just weak head normal form)
--evalFull _ e = e
--TODO implement properly
\ No newline at end of file
--TODO implement properly
concatRecord (Record r1) (Record r2) = Record (r1 ++ r2)
\ No newline at end of file
......@@ -2,6 +2,7 @@ import Types
import Debug
import Eval
import System.IO
import System.Environment
import CSV
import Lexer
import Parser
......@@ -11,7 +12,12 @@ parse :: String -> Program
parse = parseSource.alexScanTokens
--outline
main = interpret "sampleprogram.txt"
main = do
args <- getArgs
case args of
(srcname:_) -> interpret srcname
_ -> interpret "q1.txt"
interpret :: FilePath -> IO () -- the main function, takes in file name, prints out result
interpret sourceFName = do
......
......@@ -26,8 +26,9 @@ false {\s -> TokenFalse }
\) {\s -> TokenRightBracket }
\; {\s -> TokenSemiCol }
\\ {\s -> TokenLambda }
--\, {\s -> TokenComma }
\, {\s -> TokenComma }
\. {\s -> TokenFullStop }
x {\s -> TokenXProduct }
$lower [$lower $digit \_ \']* {\s -> TokenVarName s }
$upper[$alpha]* {\s -> TokenSetName s }
$digit+ {\s -> TokenNat (read s) }
......@@ -56,6 +57,7 @@ data Token =
TokenComma |
TokenFullStop |
TokenInSet |
TokenXProduct |
TokenOutSet
deriving (Eq, Show)
}
......@@ -29,6 +29,7 @@ import Types
'\\' { TokenLambda }
',' { TokenComma }
'.' { TokenFullStop }
x { TokenXProduct }
%right "->"
%left "/=" "==" ';'
......@@ -49,6 +50,8 @@ SetFuncCalls : SetFuncCall {[$1]}
SetFuncCall : filter '['SetName']' '('Func')' {FuncCall (PredefFunc Filter) [Var $3] [$6]}
| filter '('Func')' {FuncCall (PredefFunc Filter) [] [$3]}
| SetName x SetName {FuncCall (PredefFunc XProduct) (map Var [$1, $3]) []}
Func : '\\' '(' VarNames ')' "->" Expr {FuncDef [] $3 $6}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment