]> ruin.nu Git - proglang.git/blob - documentation
compiler seems to be working
[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 (v is used for values, e for expressions, s for statements, c is the context)
17
18
19 [Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
20
21 <e1 o e2,c> => <v,c''> <= <e1,c> => <v1,c'>  <e2,c'> => <v2,c''> v is the result of using operator o on v1 and v2
22
23
24 [Assignment]
25
26 <i := e,c> => c'[i -> v] <= <e,c> => <v,c'>
27
28 Assign the value v to i in the first scope i is found in.
29
30 [ENeg]
31
32 <e,c> => <-v,c'> <= <e,c> => <v,c'>
33
34
35 [ENot]
36
37 <e,c> => <not v,c'> <= <e,c> => <v,c'>
38
39 [EVar]
40
41 <i,c> => <c(i),c>
42
43 [EInt]
44
45 <n,c> => <n,c>
46
47 [EBool]
48
49 <b,c> => <b,c>
50
51 [EReadI,EReadB]
52
53 <c> => <v,c'> <= <IO,c> => <v,c'>
54
55 [EPost]
56
57 <i,c> => <v,c[i->v']> <= c(i) => v, v±1 => v'
58
59 Look up the variable, add/subtract 1 from the value then return the old value and context with modified value
60
61 [SExp]
62
63 <e,c> => c' <= <e,c> => <v,c'>
64
65 [SBlock]
66
67 <SBlock s,c> => c'''  <= push(c) => c' <s,c'> => c'' pop(c'') => c'''
68
69 Push a new scope onto the context, execute the statements in this context and the pop the scope from the context
70
71 [SEQ]
72
73 <s1;s2,c> => c'' <= <s1,c> => c' <s2,c'> => c''
74
75 [SIf]
76
77 <if e s1 s2,c> => pop(c''') <= <e,c> => <true,c'> push(c') <s1,c''> => c'''
78
79 <if e s1 s2,c> => pop(c''') <= <e,c> => <false,c'> push(c') <s2,c''> => c'''
80
81
82 [SWhile]
83
84 <while e s,c> => c' => <e,c> => <false,c'>
85
86 <while e s,c> => pop(c''') => <e,c> => <true,c'> push(c') => c'' <s,c''> => c'''
87
88
89 [SDecl]
90
91 <i := e,c> => c'[i->v] <= <e,c> => <v,c'>
92
93 Adds i with value v to the current scope in the context
94
95 [SDeclD]
96
97 <int i,c> => c[i->0]
98 <bool i,c> => c[i->false]
99
100 Adds i with default value in the current scope
101
102 [SNoop]
103
104 <SNoop,c> => c
105
106 SNoops does nothing so the same context is returned
107
108 [SPrint]
109
110 <e,c> => c'' <= <e,c> => <v,c'> <IO v,c'>  => c''