1 ####### DOCUMENTATIATOIAITAT ION ########
3 Functions has been added, with c style syntax.
10 -c : Compile [file], interprets if it isn't specified
12 if no arguments are specified then the file is interpreted
15 Interpret.hs: Handles the interpretation of a program
17 Compile.hs: Compiles the program into a c program
19 Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
21 Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
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.
26 Additions which comes from the extension:
31 (t is used for types, T is the context, and + is used for in)
35 T+ i (es) : t <= i(ts):t in T & T+ es:ts
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
41 T+ return e <= e:t & ret(t) in T
43 return typechecks if e returns the same type as the current context
47 T+ t i (ds) => T' <= ds:ts & T,i(ts):t => T'
49 Adds the function with parameter types and returntype to the context
51 T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t
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
57 T+ fs ss <= T+,fs => T' && T'+ fs && T'+ ss
59 The program typechecks if all the functions and all the statements typechecks in the context with all functions added to it.
64 (v is used for values, e for expressions, s for statements, c is the context)
68 <i (es), c> => <o'''(ret),o'> <= <es,c> => <vs,c'>, c(i) => <ds,ss>, c'[clearVars,ds->vs] => c'' <ss,o''> => o'''
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.
75 <return e,c> <= <e,c> => <v,c'>, c'[ret->v], STOP
77 Evaluate the expression, add the value as return value to the state and stop the execution of the state
81 <t i (ds) ss, c> => c[i-><ds,ss>]
83 Adds the function i with parameters ds and body ss to the context
87 <fs ss, c> => c'' <= c[fs] => c', <ss,c'> => c''
89 Add all the function to the context and execute the statements in this context