]> ruin.nu Git - proglang.git/blob - documentation
updating documentation
[proglang.git] / documentation
1 ####### DOCUMENTATIATOIAITAT ION ########
2
3 Usage:
4
5 ./CompInt [-c] [file]
6
7 -c : Compile [file], interprets if it isn't specified
8
9 if no arguments are specified then the file is interpreted
10
11 Files:
12 Interpret.hs: Handles the interpretation of a program
13
14 Compile.hs: Compiles the program into a c program
15
16 Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
17
18 Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
19
20 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.
21
22
23 semantic rules
24 ++++++++++++
25
26
27 (v is used for values, e for expressions, s for statements, c is the context)
28
29
30 [Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
31
32 <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
33
34
35 [Assignment]
36
37 <i := e,c> => c'[i -> v] <= <e,c> => <v,c'>
38
39 Assign the value v to i in the first scope i is found in.
40
41 [ENeg]
42
43 <e,c> => <-v,c'> <= <e,c> => <v,c'>
44
45
46 [ENot]
47
48 <e,c> => <not v,c'> <= <e,c> => <v,c'>
49
50 [EVar]
51
52 <i,c> => <c(i),c>
53
54 [EInt]
55
56 <n,c> => <n,c>
57
58 [EBool]
59
60 <b,c> => <b,c>
61
62 [EReadI,EReadB]
63
64 <c> => <v,c'> <= <IO,c> => <v,c'>
65
66 [EPost]
67
68 <i,c> => <v,c[i->v']> <= c(i) => v, v±1 => v'
69
70 Look up the variable, add/subtract 1 from the value then return the old value and context with modified value
71
72 [SExp]
73
74 <e,c> => c' <= <e,c> => <v,c'>
75
76 [SBlock]
77
78 <SBlock s,c> => c'''  <= push(c) => c' <s,c'> => c'' pop(c'') => c'''
79
80 Push a new scope onto the context, execute the statements in this context and the pop the scope from the context
81
82 [SEQ]
83
84 <s1;s2,c> => c'' <= <s1,c> => c' <s2,c'> => c''
85
86 [SIf]
87
88 <if e s1 s2,c> => pop(c''') <= <e,c> => <true,c'> push(c') <s1,c''> => c'''
89
90 <if e s1 s2,c> => pop(c''') <= <e,c> => <false,c'> push(c') <s2,c''> => c'''
91
92
93 [SWhile]
94
95 <while e s,c> => c' => <e,c> => <false,c'>
96
97 <while e s,c> => pop(c''') => <e,c> => <true,c'> push(c') => c'' <s,c''> => c'''
98
99
100 [SDecl]
101
102 <i := e,c> => c'[i->v] <= <e,c> => <v,c'>
103
104 Adds i with value v to the current scope in the context
105
106 [SDeclD]
107
108 <int i,c> => c[i->0]
109 <bool i,c> => c[i->false]
110
111 Adds i with default value in the current scope
112
113 [SNoop]
114
115 <SNoop,c> => c
116
117 SNoops does nothing so the same context is returned
118
119 [SPrint]
120
121 <e,c> => c'' <= <e,c> => <v,c'> <IO v,c'>  => c''