]> ruin.nu Git - proglang.git/blob - documentation
Interpreter works
[proglang.git] / documentation
1 ####### DOCUMENTATIATOIAITAT ION ########
2
3
4 Files:
5 Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
6
7 Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
8
9 Abssyntax.hs, Parsyntax.y, Lexsyntax.x,ErrM.hs,Printsyntax.hs,Skelsyntax.hs: The files generated by bnfc, only modification is the removal of the Bool type in Abssyntx.hs so haskell's internal type can be used.
10
11
12 typing rules
13 ++++++++++++
14
15
16 (t is used for types, T is the context, and + is used for in)
17
18
19 [Eq, NEq]
20
21 T+ e1 Eq e2:bool  <=  T+ e1:t  &  T+ e2:t
22
23 If e1 and e2 are of the same type, then Eq or NEq return bool
24
25
26 [Plus, Minus, Times, Div]
27
28 T+ e1 Plus e2:int  <=  T+ e1:int  &  T+ e2:int
29
30 The operators Plus/Minus/Times/Div return int if both operands are ints
31
32
33 [Lt, ELt, Gt, EGt]
34
35 T+ e1 Lt e2:bool  <=  T+ e1:int  &  T+ e2:int
36
37 The operators Lt/ELt/Gt/EGt return bool if both operands are ints
38
39
40 [Assignment]
41
42 T+ i := e:t  <=  i:t in T  &  T+ e:t
43
44 The assignemnt of e to i returns type t if both i and e have type t.
45
46
47 [ENeg]
48
49 T+ ENeg e:int  <=  T+ e:int
50
51 ENeg e returns int if e is of type int
52
53 [ENot]
54
55 T+ ENot e:bool  <=  e:bool
56
57 ENot e returns bool if e is of type bool
58
59 [EVar]
60
61 T+ i:t <= i:t in T
62
63 i has type t if i is defined in the context with type t.
64
65 [EInt]
66
67 T+ n:int
68
69 n has type int
70
71 [EBool]
72
73 T+ b:bool
74
75 b has type bool
76
77 [EReadI]
78
79 T+ n:int
80
81 EReadI returns an int
82
83 [EReadB]
84
85 T+ b:bool
86
87 EReadB returns a bool
88
89 [EPost]
90
91 T+ EPost i:int <= i:int in T
92
93 EPost i is of type int if i is defined in T with type int.
94
95 [SExp]
96
97 T+ e   <=  T+ e:t
98
99 [SBlock]
100
101 T+ s;SBlock ss <= T+ s => T' , T'+ ss => T''
102
103 the first statment s, in the block, is typechecked in the context T and returns the context T', the rest of the block is then recursively typeckecked in the context T' 
104
105
106 [SIf]
107
108 T+ if e then s1 else s2  <=  T+ e:bool  &  T+ s1  &  T+ s2
109
110 if e is of type bool and s1 and and s2 typechecks in the context T, then the same context is returned
111
112
113 [SWhile]
114
115 T+ while e do s  <=  T+ e:bool  &  T+ s
116
117 If e is of type bool and s typechecks in context T then the same context is returned
118
119
120
121 [SDecl]
122
123 T+ t i = e => T,i:t  <=  i not in T  &  e:t 
124
125 if i and e are of the same type and i is not declared in the current scope then i is added with type t to the context.
126
127 [SDeclD]
128
129 T+ t i => T,i:t  <=  i not in T
130
131 if i is not declared in the current scope, then i is added to the context with type t
132
133 [SNoop]
134
135 T+ s
136
137 SNoops does nothing so the same context is returned
138
139 [SPrint]
140
141 T+ e <= T+ e:t
142
143 if e has type t then SPrint returns the same context