Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Commit bc7c1f70 authored by pm3g19's avatar pm3g19
Browse files

[COLLAB]

parent 4ffbb4a8
......@@ -33,7 +33,13 @@ evalFinal :: Expr -> Expr -- whnf set to ready set
evalFinal = evalFull []
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
......@@ -43,12 +49,13 @@ loadInputFile name = do
return output
where
toRecord stringList = Record $ map ((String).stripLeadingAndTrailingWhitespace) stringList
toRecord stringList = Record $ map ((String).stripWhitespace) stringList
stripLeadingAndTrailingWhitespace = stripTrailingWhitespace.dropWhile (==' ')
stripWhitespace = stripTrailingWhitespace.dropWhile (==' ')
stripTrailingWhitespace (' ':xs) = let remainder = stripTrailingWhitespace xs in
if null remainder then [] else ' ':remainder
stripTrailingWhitespace (x:xs) = x : stripTrailingWhitespace xs
stripTrailingWhitespace [] = []
......@@ -5,32 +5,34 @@ module Lexer where
%wrapper "basic"
$digit = 0-9
$alpha = [a-zA-Z]
$lower = [a-z]
$upper = [A-Z]
tokens :-
$white+ ;
"--".* ;
Filter {\s -> TokenFilter }
SetName {\s -> TokenSetName s }
Func {\s -> TokenFunc }
Nat {\s -> TokenNat (read s) }
VarName {\s -> TokenVarName s }
Record {\s -> TokenRecord }
true {\s -> TokenTrue }
false {\s -> TokenFalse }
String {\s -> TokenString s }
'[' {\s -> TokenLeftSqBracket }
']' {\s -> TokenRightSqBracket }
"->" {\s -> TokenArrow }
"==" {\s -> TokenisEqual }
"/=" {\s -> TokenisNotEqual }
'(' {\s -> TokenLeftBracket }
')' {\s -> TokenRightBracket }
';' {\s -> TokenApp }
'\\' {\s -> TokenLambda }
',' {\s -> TokenComma }
'.' {\s -> TokenFullstop }
in {\s -> TokenInSet }
out {\s -> TokenOutSet }
$white+ ;
"--".* ;
filter {\s -> TokenFilter }
$upper[$alpha]* {\s -> TokenSetName s }
Func {\s -> TokenFunc }
$digit+ {\s -> TokenNat (read s) }
$lower [$lower $digit \_ \']* {\s -> TokenVarName s }
Record {\s -> TokenRecord }
true {\s -> TokenTrue }
false {\s -> TokenFalse }
$[$alpha $digit]* {\s -> TokenString s }
'[' {\s -> TokenLeftSqBracket }
']' {\s -> TokenRightSqBracket }
"->" {\s -> TokenArrow }
"==" {\s -> TokenisEqual }
"/=" {\s -> TokenisNotEqual }
'(' {\s -> TokenLeftBracket }
')' {\s -> TokenRightBracket }
';' {\s -> TokenApp }
'\\' {\s -> TokenLambda }
',' {\s -> TokenComma }
'.' {\s -> TokenFullstop }
in {\s -> TokenInSet }
out {\s -> TokenOutSet }
{
--token type:
data Token =
......
{
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]}
| SetNames, SetName
VarNames : VarName
| VarName',' VarNames
%right "->"
%left "/=" "==" ';'
%%
Prog : '.' in SetNames '.' out SetFuncCall {($3,$6)}
SetNames : Setname {[$1]}
| SetNames ',' setName { }
VarNames : var {Var $1}
| var ',' VarNames {Var $1 $3}
SetSetFuncCalls : SetFuncCall {[SetFuncCall]}
| SetFuncCall; SetFuncCalls {SetFuncCall:SetFuncCalls}
| SetFuncCall; SetFuncCalls {SetFuncCall:SetFuncCalls}
SetFuncCall : filter '['SetName']' '('Func')' {FuncCall (PredefFunc Filter) [$3] [$6]}
--filter[A](\r -> r[2] /= "")
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'['Nat']' {FuncCall (PredefFunc RecordIndex) [] [$3]}
| String {String $1}
| VarName {Var $1}
| Record {$1}
| true {Boolean True}
| false {Boolean False}
| Expr'['Nat']' {FuncCall (PredefFunc RecordIndex) [] [$3]}
| String {String $1}
| VarName {Var $1}
| Record {$1}
| true {Boolean True}
| false {Boolean False}
Record : '['Exprs']' {Record $2}
Exprs : Expr {[$1]}
| Expr','Exprs {$1:$2}
| Expr','Exprs {$1:$2}
{
}
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
......@@ -9,7 +9,6 @@ readCSV fname = do
readCSVString :: String -> [[String]]
readCSVString whole = [splitElem ',' line | line <- splitElem '\n' whole]
splitElem :: Eq a => a -> [a] -> [[a]]
splitElem elem = split (/=elem)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment