INTERPERTER Help Pattern Matching

GodIsGreat (IRC) 2018-03-11 04:29:21.312001 UTC

1-- function support
2-- type system support
3-- branching support
4-- local delarations
5
6
7
8data RoboProg = RoboProg [DecType] [FunctionDef]
9 deriving (Eq,Show)
10
11data FunctionDef = FunDef FunName Type [(Pattern,[Symbol],Exp)] Arity
12
13type Arity = Int
14
15data Aexp = AVal Int
16 | AVar [Literal]
17 | Mult Aexp Aexp
18 | Add Aexp Aexp
19 | Sub Aexp Aexp
20 deriving Show
21
22data Bexp = TRUE
23 | FALSE
24 | Neg Bexp
25 | Or Bexp Bexp
26 | And Bexp Bexp
27 | Le Aexp Aexp
28 | Eq Aexp Aexp
29 | Ge Aexp Aexp
30 deriving Show
31
32
33data Exp = ValE Value
34 | VarE Symbol Type
35 | LetE [Binding] Exp
36 | CaseE Exp [Branch]
37 | FunCallE FunName [Value] Type -- the type here is the expected result type of function application to argument values
38 | Seq Exp Exp
39 deriving (Eq,Show)
40
41data Binding = Binding Symbol Type Exp
42 deriving (Eq,Show)
43
44data Branch = Branch Value Bexp Exp
45 deriving (Eq,Show)
46
47data Value = PrimValue PrimType [Literal]
48 | FunVal FunName Type Env -- Change name of Env it's the [Applied arguments]
49 | SysCall
50 | LocalCall
51 deriving (Eq,Show)
52
53type Symbol = [Char]
54
55data Type = PrimT PrimType
56 | FunctionT Type Type
57 | UserT DecType
58 deriving (Eq,Show)
59
60data DecType = DecType TypeConsName [TypeVariables] [DataConstructor] -- nonEmpty
61 deriving (Eq,Show)
62
63data DataConstructor = SingleCons DataConsName
64 | DataCons DataConsName [TypeParams] --nonEmpty
65 deriving (Eq,Show)
66
67data TypeParams = ConcreteType Type
68 | TypeParams TypeVariables
69 deriving (Eq,Show)
70
71type TypeConsName = [TypeSymbol] --nonEmpty
72type DataConsName = [TypeSymbol] --nonEmpty
73type FunName = [Literal] --nonEmpty
74type TypeVariables = Symbol
75
76data TypeSymbol = A | B | C | D
77 deriving (Eq,Show)
78
79newtype PrimType = PrimType [TypeSymbol]
80 deriving (Eq,Show)
81
82type Literal = Char
83
84type Env = [(Symbol,Value)]
85
86data SysCall = ReadCell RelativeCellMemAdd (Maybe RoboMemAdd)
87 | WriteCell RelativeCellMemAdd MemAddress
88 | Turn Direction
89 deriving (Eq,Show)
90
91data MemAddress = CAddress RelativeCellMemAdd | RAddress RoboMemAdd
92 deriving (Eq,Show)
93
94data RelativeCellMemAdd = RelativeCellMemAdd Direction CellMemoryType Index
95 deriving (Eq,Show)
96
97data RoboMemAdd = RoboMemAdd RoboMemoryType Index
98 deriving (Eq,Show)
99
100type CellMemoryType = String --- this has to be modified
101type RoboMemoryType = String --- this has to be modified
102
103data Direction = LEFT | RIGHT | FORWARD | BACKWARD | FORWARDLEFT | FORWARDRIGHT | BACKWARDLEFT | BACKWARDRIGHT | CURRENT
104 deriving (Eq,Show)
105
106type Index = Int
107
108data LocalCall = WriteRobo RoboMemAdd WriteContent
109 deriving (Eq,Show)
110
111data WriteContent = MemContent RoboMemAdd
112 | ValContent Value
113 deriving (Eq,Show)