Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PLC COMP 2212
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
es6g19
PLC COMP 2212
Commits
3c39d92e
Commit
3c39d92e
authored
4 years ago
by
Btadford
Browse files
Options
Downloads
Patches
Plain Diff
Problem2Solved
parent
598b548e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Main.hs
+21
-5
21 additions, 5 deletions
Main.hs
with
21 additions
and
5 deletions
Main.hs
+
21
−
5
View file @
3c39d92e
...
...
@@ -3,6 +3,7 @@ import CQLGrammar
import
System.Environment
import
Control.Exception
import
System.IO
import
Data.List
main
::
IO
()
main
=
catch
readTest
noLex
...
...
@@ -31,6 +32,7 @@ evaluateCQL f = do putStrLn ("Placeholder to evaluate")
-- For column n you get the nth element from each row in TableType
type
TableType
=
[[
String
]]
type
Tables
=
[(
String
,
TableType
)]
type
RowType
=
[
String
]
-- Recurses through Function types to evaluate
...
...
@@ -38,11 +40,11 @@ evaluateFunc :: Function -> Tables -> IO TableType
evaluateFunc
(
TmSeq
x
@
(
TmLet
var
def
)
f2
)
tables
=
do
table
<-
createDef
var
def
let
tables'
=
table
:
tables
evaluateFunc
f2
tables'
evaluateFunc
(
TmSeq
f1
f2
)
tables
=
evaluateFunc
f1
tables
evaluateFunc
(
TmJoin
x
y
)
tables
=
do
x'
<-
selectFromTable
x
tables
y'
<-
selectFromTable
y
tables
let
result
=
joinTables
x'
y'
return
result
--
evaluateFunc (TmSeq f1 f2) tables = evaluateFunc f1 tables
--
evaluateFunc (TmJoin x y) tables = do x' <- selectFromTable x tables
--
y' <- selectFromTable y tables
--
let result = joinTables x' y'
--
return result
-- Selects the desired data from a table
selectFromTable
::
Select
->
Tables
->
IO
[
TableType
]
...
...
@@ -72,6 +74,20 @@ conjunction table1 [] = []
conjunction
[]
table2
=
[]
conjunction
table1
table2
=
(
map
(
++
head
table2
)
table1
)
++
conjunction
(
table1
)
(
tail
table2
)
-- getRow table1 = head table1
permuteArray
::
TableType
->
TableType
permuteArray
[]
=
[]
permuteArray
table1
=
sort
(
(
permuteAndMatch
(
head
table1
))
:
permuteArray
(
tail
table1
)
)
permuteAndMatch
::
RowType
->
RowType
permuteAndMatch
[]
=
[]
permuteAndMatch
row
|
length
rowString
/=
3
=
[]
|
rowString
!!
0
==
rowString
!!
1
=
[
([
rowString
!!
2
]
++
[
rowString
!!
0
]
)]
|
otherwise
=
[]
where
rowString
=
head
row
-- TODO: Joins two lists of tables together
--joinTables :: [TableType] -> [TableType] -> TableType
...
...
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