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
048a566d
Commit
048a566d
authored
4 years ago
by
pm3g19
Browse files
Options
Downloads
Patches
Plain Diff
[NOCOMPILE] Started working on interpreter.
parent
113cd751
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
Debug.hs
+2
-0
2 additions, 0 deletions
Debug.hs
Eval.hs
+27
-0
27 additions, 0 deletions
Eval.hs
Interpreter.hs
+31
-0
31 additions, 0 deletions
Interpreter.hs
with
60 additions
and
0 deletions
Debug.hs
0 → 100644
+
2
−
0
View file @
048a566d
module
Debug
where
notImplemented
=
error
"Not implemented yet"
This diff is collapsed.
Click to expand it.
Eval.hs
0 → 100644
+
27
−
0
View file @
048a566d
eval
::
ResultEnvironment
->
Expr
->
Expr
--only focus on one expression
type
Environment
=
ResultEnvironment
findVar
::
Environment
->
SymbolName
->
Expr
findVar
=
notImplemented
addVar
::
Environment
->
SymbolName
->
Expr
->
Environment
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)
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
)
.
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
(
IsEqual
)
->
let
(
e1
:
e2
:
_
)
=
args
in
Boolean
(
eval'
e1
==
eval'
e2
)
(
RecordIndex
)
->
let
(
Record
recordData
,
Int
index
)
=
(
eval'
$
args
!!
0
,
eval'
$
args
!!
1
)
in
recordData
!!
index
--implement later
--(Map) -> Set $ (map (\r -> FuncCall predicate [] [r]) inputRecords)
(
FuncDef
setParams
argParams
body
)
->
eval
new_env
body
where
newEnv
=
foldl
(
\
env
entry
@
(
name
,
expr
)
->
addVar
env
name
expr
)
env
--adds entries to environment
-- TODO FIx
(
Var
name
)
->
findVar
env
name
_
->
expr
This diff is collapsed.
Click to expand it.
Interpreter.hs
0 → 100644
+
31
−
0
View file @
048a566d
import
Types
import
Debug
type
Control
=
(
ResultEnvironment
,
[
Expr
])
type
ResultEnvironment
=
[(
SymbolName
,
Expr
)]
-- (result of last calculation, other bindings e.g. let statements)
prepare
::
Program
->
IO
Control
-- takes in the AST for the program, reads the csv files and prepares the environment based on the CSV files
prepare
(
inputSets
,
instructions
)
=
zipM
(
environment
,
return
instructions
)
where
environment
=
fmap
(
zip
inputSets
)
$
loadInputFiles
inputSets
---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)
--------------------------------------------
programStep
::
Control
->
Control
-- updates environment and list
programStep
=
notImplemented
--------------------------------------------
loadInputFiles
::
[
String
]
->
IO
[[
String
]]
loadInputFiles
=
mapM
readCSV
readCSV
::
FilePath
->
IO
[[
String
]]
readCSV
_
=
error
""
\ No newline at end of file
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