Commit 33c138b6 authored by pm3g19's avatar pm3g19
Browse files

Some improvements for data structures

parent 29f6828b
......@@ -3,22 +3,26 @@ type Program = (InputSymbols,Output)
type SymbolName = String
type InputSymbols = [String] -- .in section
type Output = [OutputLine] -- .out section
data OutputLine = Let SymbolName Expr | Expr -- Expr always a function call for a set function, but not enforced by AST.
--type Output = [OutputLine] -- .out section
--data OutputLine = Let SymbolName Expr | Expr -- Expr always a function call for a set function, but not enforced by AST.
type Output = [Expr]
data PredefFunc = XProduct | XXProduct | IsEqual | IsNotEqual | Add --operators
| Map | Filter
| RecordIndex -- [] operator
| IsEmpty | NotEmpty -- string functions
deriving (Show, Eq)
--n.b. these definitions do not enforce type checking! The use of any function or operator will be associated with a FuncCall.
--Therefore, it is possible to have ASTs with ridiculous things where e.g. a XX product is applied to and int and a String, or a function call has an Int as a function!
--These issues will be checked via the type checker after the AST has been built.
-- filter [A] (\(r) -> r[1] == "hello")
-- FuncCall (PredefFunc Filter) [Var "A"] [FuncDef [] ["r"] [(FuncCall (PredefFunc IsEqual) [] (r[1]) ("hello"))]]
data Expr = FuncCall {func::Expr, inputSets::[Expr], args::[Expr]} -- args: function to call, input sets, extra argument. Applicable for all kinds of functions: the set functions e.g. filter, map or simple functions or even the operators e.g. ==, /= ! We don't define separate expr for each operator
| FuncDef {name::SymbolName, inputSetNames::[SymbolName], argsNames::[SymbolName], body::Expr} -- function definition
-- | FuncDef {name::SymbolName, inputSetNames::[SymbolName], argsNames::[SymbolName], body::Expr} -- function definition
| FuncDef {inputSetNames::[SymbolName], argsNames::[SymbolName], body::Expr} -- function definition
| If Expr Expr Expr
| Set [Expr]
| Tuple [Expr]
......@@ -28,5 +32,6 @@ data Expr = FuncCall {func::Expr, inputSets::[Expr], args::[Expr]} -- args: func
| Int Int
| String String
| Boolean Bool
deriving (Show, Eq)
data Parameter = NamedParam SymbolName | TupleMatch [SymbolName]
\ No newline at end of file
Supports Markdown
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