]> ruin.nu Git - proglang.git/blob - documentation
minor change
[proglang.git] / documentation
1 ####### DOCUMENTATIATOIAITAT ION ########
2
3 Functions has been added, with c style syntax.
4
5
6 Usage:
7
8 ./CompInt [-c] [file]
9
10 -c : Compile [file], interprets if it isn't specified
11
12 if no arguments are specified then the file is interpreted
13
14 Files:
15 Interpret.hs: Handles the interpretation of a program
16
17 Compile.hs: Compiles the program into a c program
18
19 Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
20
21 Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
22
23 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.
24
25
26 Additions which comes from the extension:
27
28 typing rules
29 ++++++++++++
30
31 (t is used for types, T is the context, and + is used for in)
32
33 [EFunc]
34
35 T+ i (es) : t <= i(ts):t in T & T+ es:ts 
36
37 The functioncall of i returns t if i is in the context with returntype t and the types of the argument expressions matches those in the parameter list
38
39 [SReturn]
40
41 T+ return e <= e:t & ret(t) in T
42
43 return typechecks if e returns the same type as the current context
44
45 [Func]
46
47 T+ t i (ds) => T' <= ds:ts & T,i(ts):t => T'
48
49 Adds the function with parameter types and returntype to the context
50
51 T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t
52
53 the function i typechecks if the body typechecks in the context where all other variables has been removed and the return type and paramters has been added and that the last statement is a return with the right type
54
55 [Program]
56
57 T+ fs ss <= T+,fs => T' && T'+ fs && T'+ ss
58
59 The program typechecks if all the functions and all the statements typechecks in the context with all functions added to it.
60
61 semantic rules
62 ++++++++++++
63
64 (v is used for values, e for expressions, s for statements, c is the context)
65
66 [EFunc]
67
68 <i (es), c> => <o'''(ret),o'>  <= <es,c> => <vs,c'>, c(i) => <ds,ss>, c'[clearVars,ds->vs] => c'' <ss,o''> => o'''
69
70 Evaluate the arguments in order, find function definition, remove the old variables and add values from the arguments to the parameters. execute the body until retun. Return the value from the return state and the state from the argument expressions.
71
72
73 [SReturn]
74
75 <return e,c> => c'[ret->v] <= <e,c> => <v,c'>
76
77 Evaluate the expression, add the value as return value to the state and stop the execution of the state
78
79 [Func]
80
81 <t i (ds) ss, c> => c[i-><ds,ss>]
82
83 Adds the function i with parameters ds and body ss to the context
84
85 [Program]
86
87 <fs ss, c> => c'' <= c[fs] => c', <ss,c'> => c''
88
89 Add all the function to the context and execute the statements in this context
90
91 [SEQ]
92
93 <s1;s2,c> => c' <= <s1,c> => c', c'(ret)
94
95 If the context returned by s1 contains a return-value, return this context without executing the next statement.
96
97 [SWhile]
98
99 <while e s,c> => c''' => <e,c> => <true,c'> push(c') => c'' <s,c''> => c''', c'''(ret)
100
101 If the context returned by the body contains a return-value, return this context and don't try to run the loop again.