Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp2212-cw-2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PLC
comp2212-cw-2021
Commits
d4b0e894
Commit
d4b0e894
authored
4 years ago
by
pm3g19
Browse files
Options
Downloads
Patches
Plain Diff
Added support for cartesian product
parent
492e7639
No related branches found
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
A.csv
+3
-0
3 additions, 0 deletions
A.csv
B.csv
+3
-0
3 additions, 0 deletions
B.csv
Eval.hs
+8
-4
8 additions, 4 deletions
Eval.hs
Interpreter.hs
+7
-1
7 additions, 1 deletion
Interpreter.hs
Lexer.x
+3
-1
3 additions, 1 deletion
Lexer.x
Parser.y
+3
-0
3 additions, 0 deletions
Parser.y
with
27 additions
and
6 deletions
A.csv
0 → 100644
+
3
−
0
View file @
d4b0e894
patryk,malinowski
maram, jones
jeffrey,sylvester
This diff is collapsed.
Click to expand it.
B.csv
0 → 100644
+
3
−
0
View file @
d4b0e894
jian,shi
andrew,sogokon
julian,rathke
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Eval.hs
+
8
−
4
View file @
d4b0e894
...
@@ -25,6 +25,9 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
...
@@ -25,6 +25,9 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
RecordIndex
->
let
(
Record
recordData
:
Int
index
:
_
)
=
(
map
eval'
args
)
in
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
--implement later
--(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
...
@@ -49,3 +52,4 @@ evalFull = eval
...
@@ -49,3 +52,4 @@ evalFull = eval
--evalFull env (Set xs) = Set (map (eval env) xs) -- evaluates expression fully (not just weak head normal form)
--evalFull env (Set xs) = Set (map (eval env) xs) -- evaluates expression fully (not just weak head normal form)
--evalFull _ e = e
--evalFull _ e = e
--TODO implement properly
--TODO implement properly
concatRecord
(
Record
r1
)
(
Record
r2
)
=
Record
(
r1
++
r2
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Interpreter.hs
+
7
−
1
View file @
d4b0e894
...
@@ -2,6 +2,7 @@ import Types
...
@@ -2,6 +2,7 @@ import Types
import
Debug
import
Debug
import
Eval
import
Eval
import
System.IO
import
System.IO
import
System.Environment
import
CSV
import
CSV
import
Lexer
import
Lexer
import
Parser
import
Parser
...
@@ -11,7 +12,12 @@ parse :: String -> Program
...
@@ -11,7 +12,12 @@ parse :: String -> Program
parse
=
parseSource
.
alexScanTokens
parse
=
parseSource
.
alexScanTokens
--outline
--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
::
FilePath
->
IO
()
-- the main function, takes in file name, prints out result
interpret
sourceFName
=
do
interpret
sourceFName
=
do
...
...
This diff is collapsed.
Click to expand it.
Lexer.x
+
3
−
1
View file @
d4b0e894
...
@@ -26,8 +26,9 @@ false {\s -> TokenFalse }
...
@@ -26,8 +26,9 @@ false {\s -> TokenFalse }
\) {\s -> TokenRightBracket }
\) {\s -> TokenRightBracket }
\; {\s -> TokenSemiCol }
\; {\s -> TokenSemiCol }
\\ {\s -> TokenLambda }
\\ {\s -> TokenLambda }
--
\, {\s -> TokenComma }
\, {\s -> TokenComma }
\. {\s -> TokenFullStop }
\. {\s -> TokenFullStop }
x {\s -> TokenXProduct }
$lower [$lower $digit \_ \']* {\s -> TokenVarName s }
$lower [$lower $digit \_ \']* {\s -> TokenVarName s }
$upper[$alpha]* {\s -> TokenSetName s }
$upper[$alpha]* {\s -> TokenSetName s }
$digit+ {\s -> TokenNat (read s) }
$digit+ {\s -> TokenNat (read s) }
...
@@ -56,6 +57,7 @@ data Token =
...
@@ -56,6 +57,7 @@ data Token =
TokenComma |
TokenComma |
TokenFullStop |
TokenFullStop |
TokenInSet |
TokenInSet |
TokenXProduct |
TokenOutSet
TokenOutSet
deriving (Eq, Show)
deriving (Eq, Show)
}
}
This diff is collapsed.
Click to expand it.
Parser.y
+
3
−
0
View file @
d4b0e894
...
@@ -29,6 +29,7 @@ import Types
...
@@ -29,6 +29,7 @@ import Types
'\\' { TokenLambda }
'\\' { TokenLambda }
',' { TokenComma }
',' { TokenComma }
'.' { TokenFullStop }
'.' { TokenFullStop }
x { TokenXProduct }
%right "->"
%right "->"
%left "/=" "==" ';'
%left "/=" "==" ';'
...
@@ -49,6 +50,8 @@ SetFuncCalls : SetFuncCall {[$1]}
...
@@ -49,6 +50,8 @@ SetFuncCalls : SetFuncCall {[$1]}
SetFuncCall : filter '['SetName']' '('Func')' {FuncCall (PredefFunc Filter) [Var $3] [$6]}
SetFuncCall : filter '['SetName']' '('Func')' {FuncCall (PredefFunc Filter) [Var $3] [$6]}
| filter '('Func')' {FuncCall (PredefFunc Filter) [] [$3]}
| filter '('Func')' {FuncCall (PredefFunc Filter) [] [$3]}
| SetName x SetName {FuncCall (PredefFunc XProduct) (map Var [$1, $3]) []}
Func : '\\' '(' VarNames ')' "->" Expr {FuncDef [] $3 $6}
Func : '\\' '(' VarNames ')' "->" Expr {FuncDef [] $3 $6}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment