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
32db377e
Commit
32db377e
authored
Apr 27, 2021
by
pm3g19
Browse files
Options
Downloads
Patches
Plain Diff
Added semantics for let
parent
00a56b7c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Eval.hs
+16
-8
16 additions, 8 deletions
Eval.hs
Types.hs
+1
-0
1 addition, 0 deletions
Types.hs
with
17 additions
and
8 deletions
Eval.hs
+
16
−
8
View file @
32db377e
...
...
@@ -49,7 +49,7 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
Contains
->
case
args
of
(
mainString
:
containsWhat
:
_
)
->
case
(
eval'
mainString
,
eval'
containsWhat
)
of
(
String
a
,
String
b
)
->
b
`
s
ub
l
ist
`
a
(
String
a
,
String
b
)
->
Boolean
$
b
`
isS
ub
L
ist
`
a
Plus
->
let
(
e1
:
e2
:
_
)
=
args
in
case
(
eval'
e1
,
eval'
e2
)
of
(
String
a
,
String
b
)
->
String
(
a
++
b
)
...
...
@@ -67,25 +67,33 @@ eval env expr = let (eval', evalFull') = (eval env, evalFull env) in case expr o
(
Var
name
)
->
eval'
$
findVar
env
name
(
Let
_
expr
)
->
expr
control
@
(
Control
lastResult
exprs
)
->
if
null
exprs
then
lastResult
else
eval'
$
evalControl1
env
control
control
@
(
Control
lastResult
exprs
)
->
if
null
exprs
then
lastResult
else
let
(
newEnv
,
newControl
)
=
evalControl1
env
control
in
eval
newEnv
newControl
_
->
expr
evalControl1
::
Environment
->
Expr
->
Expr
evalControl1
env
(
Control
last
(
currentExpr
:
exprs
))
=
let
output
=
eval
env
currentExprFull
in
Control
outpu
t
exprs
evalControl1
::
Environment
->
Expr
->
(
Environment
,
Expr
)
evalControl1
env
(
Control
last
(
currentExpr
:
exprs
))
=
(
newEnv
,
Control
newLas
t
exprs
)
where
currentExprFull
=
case
currentExpr
of
newLast
=
eval
env
$
case
currentExpr
of
(
FuncCall
func
[]
args
)
->
FuncCall
func
[
last
]
args
_
->
currentExpr
newEnv
=
case
currentExpr
of
(
Let
var
expr
)
->
(
var
,
expr
)
:
env
_
->
env
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
concatRecord
(
Record
r1
)
(
Record
r2
)
=
Record
(
r1
++
r2
)
sublist
=
notImplemented
\ No newline at end of file
listStartsWith
,
isSubList
::
[
a
]
->
[
a
]
->
Bool
listStartsWith
=
notImplemented
-- check if first list starts with second list
isSubList
=
notImplemented
-- check if first list contains second list anywhere in it
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Types.hs
+
1
−
0
View file @
32db377e
...
...
@@ -35,6 +35,7 @@ data Expr = Control Expr [Expr] -- result of last computation, sequence of instr
|
Int
Int
|
String
String
|
Boolean
Bool
|
Let
SymbolName
Expr
-- | Nat Int
deriving
(
Show
,
Eq
)
...
...
...
...
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