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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PLC
comp2212-cw-2021
Commits
bc7c1f70
Commit
bc7c1f70
authored
4 years ago
by
pm3g19
Browse files
Options
Downloads
Patches
Plain Diff
[COLLAB]
parent
4ffbb4a8
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Interpreter.hs
+10
-3
10 additions, 3 deletions
Interpreter.hs
Lexer.x
+26
-24
26 additions, 24 deletions
Lexer.x
Parser.y
+60
-16
60 additions, 16 deletions
Parser.y
Print2DListLex.hs
+13
-0
13 additions, 0 deletions
Print2DListLex.hs
ReadCSV.hs
+0
-1
0 additions, 1 deletion
ReadCSV.hs
with
109 additions
and
44 deletions
Interpreter.hs
+
10
−
3
View file @
bc7c1f70
...
@@ -33,7 +33,13 @@ evalFinal :: Expr -> Expr -- whnf set to ready set
...
@@ -33,7 +33,13 @@ evalFinal :: Expr -> Expr -- whnf set to ready set
evalFinal
=
evalFull
[]
evalFinal
=
evalFull
[]
showFinal
::
Expr
->
IO
()
showFinal
::
Expr
->
IO
()
showFinal
=
notImplemented
showFinal
=
(
print2DList
.
sort2DListLex
.
setTo2DList
)
setTo2DList
::
Expr
->
[[
String
]]
setTo2DList
=
notImplemented
sort2DListLex
=
id
-- TODO change this
print2DList
=
notImplemented
--------------------------------------------
--------------------------------------------
loadInputFile
::
SymbolName
->
IO
Expr
loadInputFile
::
SymbolName
->
IO
Expr
...
@@ -43,12 +49,13 @@ loadInputFile name = do
...
@@ -43,12 +49,13 @@ loadInputFile name = do
return
output
return
output
where
where
toRecord
stringList
=
Record
$
map
((
String
)
.
strip
LeadingAndTrailing
Whitespace
)
stringList
toRecord
stringList
=
Record
$
map
((
String
)
.
stripWhitespace
)
stringList
strip
LeadingAndTrailing
Whitespace
=
stripTrailingWhitespace
.
dropWhile
(
==
' '
)
stripWhitespace
=
stripTrailingWhitespace
.
dropWhile
(
==
' '
)
stripTrailingWhitespace
(
' '
:
xs
)
=
let
remainder
=
stripTrailingWhitespace
xs
in
stripTrailingWhitespace
(
' '
:
xs
)
=
let
remainder
=
stripTrailingWhitespace
xs
in
if
null
remainder
then
[]
else
' '
:
remainder
if
null
remainder
then
[]
else
' '
:
remainder
stripTrailingWhitespace
(
x
:
xs
)
=
x
:
stripTrailingWhitespace
xs
stripTrailingWhitespace
(
x
:
xs
)
=
x
:
stripTrailingWhitespace
xs
stripTrailingWhitespace
[]
=
[]
stripTrailingWhitespace
[]
=
[]
This diff is collapsed.
Click to expand it.
Lexer.x
+
26
−
24
View file @
bc7c1f70
...
@@ -5,32 +5,34 @@ module Lexer where
...
@@ -5,32 +5,34 @@ module Lexer where
%wrapper "basic"
%wrapper "basic"
$digit = 0-9
$digit = 0-9
$alpha = [a-zA-Z]
$alpha = [a-zA-Z]
$lower = [a-z]
$upper = [A-Z]
tokens :-
tokens :-
$white+ ;
$white+
;
"--".* ;
"--".*
;
F
ilter {\s -> TokenFilter }
f
ilter
{\s -> TokenFilter }
SetName
{\s -> TokenSetName s }
$upper[$alpha]*
{\s -> TokenSetName s }
Func {\s -> TokenFunc }
Func
{\s -> TokenFunc }
Nat
{\s -> TokenNat (read s) }
$digit+
{\s -> TokenNat (read s) }
VarName
{\s -> TokenVarName s }
$lower [$lower $digit \_ \']*
{\s -> TokenVarName s }
Record {\s -> TokenRecord }
Record
{\s -> TokenRecord }
true {\s -> TokenTrue }
true
{\s -> TokenTrue }
false {\s -> TokenFalse }
false
{\s -> TokenFalse }
String
{\s -> TokenString s }
$[$alpha $digit]*
{\s -> TokenString s }
'[' {\s -> TokenLeftSqBracket }
'['
{\s -> TokenLeftSqBracket }
']' {\s -> TokenRightSqBracket }
']'
{\s -> TokenRightSqBracket }
"->" {\s -> TokenArrow }
"->"
{\s -> TokenArrow }
"==" {\s -> TokenisEqual }
"=="
{\s -> TokenisEqual }
"/=" {\s -> TokenisNotEqual }
"/="
{\s -> TokenisNotEqual }
'(' {\s -> TokenLeftBracket }
'('
{\s -> TokenLeftBracket }
')' {\s -> TokenRightBracket }
')'
{\s -> TokenRightBracket }
';' {\s -> TokenApp }
';'
{\s -> TokenApp }
'\\' {\s -> TokenLambda }
'\\'
{\s -> TokenLambda }
',' {\s -> TokenComma
}
','
{\s -> TokenComma }
'.' {\s -> TokenFullstop }
'.'
{\s -> TokenFullstop }
in {\s -> TokenInSet
}
in
{\s -> TokenInSet }
out {\s -> TokenOutSet
}
out
{\s -> TokenOutSet }
{
{
--token type:
--token type:
data Token =
data Token =
...
...
This diff is collapsed.
Click to expand it.
Parser.y
+
60
−
16
View file @
bc7c1f70
{
module Parser where
import Lexer
}
%name parseCalc
%tokentype {Token}
%error {parseError}
Prog : .in SetNames .out SetFuncCalls {($2, $4)}
%token
filter { TokenFilter }
in { TokenInSet }
out { TokenOutSet }
Setname { TokenSetName $$ }
function { TokenFunc }
nat { TokenNat $$ }
var { TokenVarName $$ }
Record { TokenRecord }
true { TokenTrue }
false { TokenFalse }
string { TokenString s }
'[' { TokenLeftSqBracket }
']' { TokenRightSqBracket }
"->" { TokenArrow }
"==" { TokenisEqual }
"/=" { TokenisNotEqual }
'(' { TokenLeftBracket }
')' { TokenRightBracket }
';' { TokenSemiCo }
'\\' { TokenLambda }
',' { TokenComma }
'.' { TokenFullstop }
SetNames : SetName {[$1]}
%right "->"
| SetNames, SetName
%left "/=" "==" ';'
%%
VarNames : VarName
| VarName',' VarNames
Prog : '.' in SetNames '.' out SetFuncCall {($3,$6)}
SetNames : Setname {[$1]}
| SetNames ',' setName { }
VarNames : var {Var $1}
| var ',' VarNames {Var $1 $3}
SetSetFuncCalls : SetFuncCall {[SetFuncCall]}
SetSetFuncCalls : SetFuncCall {[SetFuncCall]}
| SetFuncCall; SetFuncCalls {SetFuncCall:SetFuncCalls}
| SetFuncCall; SetFuncCalls {SetFuncCall:SetFuncCalls}
SetFuncCall : filter '['SetName']' '('Func')' {FuncCall (PredefFunc Filter) [$3] [$6]}
SetFuncCall : filter '['SetName']' '('Func')' {FuncCall (PredefFunc Filter) [$3] [$6]}
--filter[A](\r -> r[2] /= "")
Func : \'('VarNames')' -> Expr {FuncDef [] $3 $6}
Func : \'('VarNames')' -> Expr {FuncDef [] $3 $6}
--\(r) -> r[1] == "hello"
Exp : '.' in var '.' out Exp {Prog $3 $6}
| filter '[' Setname ']' Exp {Filter $3 $5}
| '(' '\\'
Expr : Expr == Expr {FuncCall (PredefFunc IsEqual) [] [$1, $3]}
Expr : Expr == Expr {FuncCall (PredefFunc IsEqual) [] [$1, $3]}
| Expr'['Nat']' {FuncCall (PredefFunc RecordIndex) [] [$3]}
| Expr'['Nat']' {FuncCall (PredefFunc RecordIndex) [] [$3]}
| String {String $1}
| String {String $1}
| VarName {Var $1}
| VarName {Var $1}
| Record {$1}
| Record {$1}
| true {Boolean True}
| true {Boolean True}
| false {Boolean False}
| false {Boolean False}
Record : '['Exprs']' {Record $2}
Record : '['Exprs']' {Record $2}
Exprs : Expr {[$1]}
Exprs : Expr {[$1]}
| Expr','Exprs {$1:$2}
| Expr','Exprs {$1:$2}
{
}
This diff is collapsed.
Click to expand it.
Print2DListLex.hs
0 → 100644
+
13
−
0
View file @
bc7c1f70
import
Data.List
import
Data.Char
import
Data.Sequence
-- | Function print2DListLex
-- 1. takes in a list of records
-- 2. prints them in lexicographical order
print2DListLex
::
[[
String
]]
->
IO
()
print2DListLex
(
record
:
records
)
=
sortBy
()
records
-- | rearran
rearrange
::
[[
String
]]
->
[[
String
]]
rearrange
records
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ReadCSV.hs
+
0
−
1
View file @
bc7c1f70
...
@@ -9,7 +9,6 @@ readCSV fname = do
...
@@ -9,7 +9,6 @@ readCSV fname = do
readCSVString
::
String
->
[[
String
]]
readCSVString
::
String
->
[[
String
]]
readCSVString
whole
=
[
splitElem
','
line
|
line
<-
splitElem
'
\n
'
whole
]
readCSVString
whole
=
[
splitElem
','
line
|
line
<-
splitElem
'
\n
'
whole
]
splitElem
::
Eq
a
=>
a
->
[
a
]
->
[[
a
]]
splitElem
::
Eq
a
=>
a
->
[
a
]
->
[[
a
]]
splitElem
elem
=
split
(
/=
elem
)
splitElem
elem
=
split
(
/=
elem
)
...
...
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