Commit 1d408e81 authored by pm3g19's avatar pm3g19
Browse files

draft of data structure for the AST

parents
module Types where
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.
data PredefFunc = XProduct | XXProduct | IsEqual | IsNotEqual | Add --operators
| Map | Filter
| RecordIndex -- [] operator
| IsEmpty | NotEmpty -- string functions
--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.
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
| If Expr Expr Expr
| Set [Expr]
| Tuple [Expr]
| Record [Expr]
| PredefFunc PredefFunc
| Var SymbolName
| Int Int
| String String
| Boolean Bool
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