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
c29081a8
Commit
c29081a8
authored
4 years ago
by
pm3g19
Browse files
Options
Downloads
Patches
Plain Diff
First fully-working version of interpreter
parent
cd95d0a2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CSV.hs
+23
-0
23 additions, 0 deletions
CSV.hs
Interpreter.hs
+2
-12
2 additions, 12 deletions
Interpreter.hs
Print2DListLex.hs
+1
-1
1 addition, 1 deletion
Print2DListLex.hs
with
26 additions
and
13 deletions
CSV.hs
+
23
−
0
View file @
c29081a8
module
CSV
where
import
System.IO
import
Data.List
readCSV
::
FilePath
->
IO
[[
String
]]
readCSV
fname
=
do
...
...
@@ -17,3 +18,25 @@ split p l = case span p l of
(
[]
,
_
)
->
[]
(
match
,
[]
)
->
[
match
]
(
match
,
_
:
rem'
)
->
match
:
split
p
rem'
print2DList
::
[[
String
]]
->
IO
()
print2DList
=
putStrLn
.
toCSVString
toCSVString
::
[[
String
]]
->
String
--F: use the function lines!
toCSVString
list
=
let
lines
=
map
(
','
`
join
`)
list
in
'
\n
'
`
join
`
lines
join
::
a
->
[[
a
]]
->
[
a
]
join
_
[]
=
[]
join
a
l
=
foldr1
(
\
s1
s2
->
s1
++
a
:
s2
)
l
sort2DListLex
::
[[
String
]]
->
[[
String
]]
sort2DListLex
=
sort
stripWhitespace
=
stripTrailingWhitespace
.
dropWhile
(
==
' '
)
stripTrailingWhitespace
(
' '
:
xs
)
=
let
remainder
=
stripTrailingWhitespace
xs
in
if
null
remainder
then
[]
else
' '
:
remainder
stripTrailingWhitespace
(
x
:
xs
)
=
x
:
stripTrailingWhitespace
xs
stripTrailingWhitespace
[]
=
[]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Interpreter.hs
+
2
−
12
View file @
c29081a8
...
...
@@ -9,7 +9,6 @@ import Debug.Trace
parse
::
String
->
Program
parse
=
parseSource
.
alexScanTokens
--outline
main
=
interpret
"sampleprogram.txt"
...
...
@@ -19,9 +18,9 @@ interpret sourceFName = do
source
<-
readFile
sourceFName
let
program
=
parse
source
-- main abstract syntax tree
(
env
,
mainExpr
)
<-
prepare
program
print
$
"Main expression "
++
show
mainExpr
--
print $ "Main expression " ++ show mainExpr
let
finalOutput
=
eval
env
mainExpr
print
$
"Final outupt: "
++
show
finalOutput
--
print $ "Final outupt: " ++ show finalOutput
showFinal
finalOutput
prepare
::
Program
->
IO
(
Environment
,
Expr
)
-- takes in the AST for the program, reads the csv files and prepares the environment based on the CSV files
...
...
@@ -44,10 +43,7 @@ showFinal = (print2DList.sort2DListLex.setTo2DList)
setTo2DList
::
Expr
->
[[
String
]]
setTo2DList
(
Set
records
)
=
map
(
map
(
\
(
String
s
)
->
s
)
.
(
\
(
Record
list
)
->
list
))
records
sort2DListLex
=
id
-- TODO change this
print2DList
::
[[
String
]]
->
IO
()
print2DList
=
notImplemented
--------------------------------------------
loadInputFile
::
SymbolName
->
IO
Expr
loadInputFile
name
=
do
...
...
@@ -58,11 +54,5 @@ loadInputFile name = do
where
toRecord
stringList
=
Record
$
map
((
String
)
.
stripWhitespace
)
stringList
stripWhitespace
=
stripTrailingWhitespace
.
dropWhile
(
==
' '
)
stripTrailingWhitespace
(
' '
:
xs
)
=
let
remainder
=
stripTrailingWhitespace
xs
in
if
null
remainder
then
[]
else
' '
:
remainder
stripTrailingWhitespace
(
x
:
xs
)
=
x
:
stripTrailingWhitespace
xs
stripTrailingWhitespace
[]
=
[]
This diff is collapsed.
Click to expand it.
Print2DListLex.hs
+
1
−
1
View file @
c29081a8
...
...
@@ -4,4 +4,4 @@ type Row = [String]
-- | Takes in a list of rows and prints them in lexicographical order
print2DListLex
::
[
Row
]
->
IO
()
print2DListLex
rows
=
return
IO
$
sort
rows
print2DListLex
rows
=
return
$
sort
rows
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