####### DOCUMENTATIATOIAITAT ION ########
+ Usage:
- Files:
- Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
-
- Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
-
- 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.
-
-
- typing rules
- ++++++++++++
-
-
- (v is used for values, e for expressions, s for statements, c is the context)
-
-
- [Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
-
- <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
-
-
- [Assignment]
-
- <i := e,c> => c'[i -> v] <= <e,c> => <v,c'>
-
- Assign the value v to i in the first scope i is found in.
-
- [ENeg]
-
- <e,c> => <-v,c'> <= <e,c> => <v,c'>
+ ./CompInt [-c] [file]
+ -c : Compile [file], interprets if it isn't specified
- [ENot]
+ if no arguments are specified then the file is interpreted
- <e,c> => <not v,c'> <= <e,c> => <v,c'>
-
- [EVar]
-
- <i,c> => <c(i),c>
-
- [EInt]
-
- <n,c> => <n,c>
-
- [EBool]
-
- <b,c> => <b,c>
-
- [EReadI,EReadB]
-
- <c> => <v,c'> <= <IO,c> => <v,c'>
-
- [EPost]
-
- <i,c> => <v,c[i->v']> <= c(i) => v, v±1 => v'
-
- Look up the variable, add/subtract 1 from the value then return the old value and context with modified value
-
- [SExp]
-
- <e,c> => c' <= <e,c> => <v,c'>
-
- [SBlock]
+ Files:
+ Interpret.hs: Handles the interpretation of a program
- <SBlock s,c> => c''' <= push(c) => c' <s,c'> => c'' pop(c'') => c'''
+ Compile.hs: Compiles the program into a c program
- Push a new scope onto the context, execute the statements in this context and the pop the scope from the context
+ Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
- [SEQ]
+ Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
- <s1;s2,c> => c'' <= <s1,c> => c' <s2,c'> => c''
+ 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.
- [SIf]
- <if e s1 s2,c> => pop(c''') <= <e,c> => <true,c'> push(c') <s1,c''> => c'''
-semantic rules
-++++++++++++
-
-
-(v is used for values, e for expressions, s for statements, c is the context)
-
-
-[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
-
-<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
-
-
-[Assignment]
-
-<i := e,c> => c'[i -> v] <= <e,c> => <v,c'>
-
-Assign the value v to i in the first scope i is found in.
-
-[ENeg]
-
-<e,c> => <-v,c'> <= <e,c> => <v,c'>
-
-
-[ENot]
-
-<e,c> => <not v,c'> <= <e,c> => <v,c'>
-
-[EVar]
-
-<i,c> => <c(i),c>
-
-[EInt]
-
-<n,c> => <n,c>
++Additions which comes from the extension:
-[EBool]
-
-<b,c> => <b,c>
-
-[EReadI,EReadB]
-
-<c> => <v,c'> <= <IO,c> => <v,c'>
-
-[EPost]
-
-<i,c> => <v,c[i->v']> <= c(i) => v, v±1 => v'
-
-Look up the variable, add/subtract 1 from the value then return the old value and context with modified value
-
-[SExp]
-
-<e,c> => c' <= <e,c> => <v,c'>
-
-[SBlock]
-
-<SBlock s,c> => c''' <= push(c) => c' <s,c'> => c'' pop(c'') => c'''
-
-Push a new scope onto the context, execute the statements in this context and the pop the scope from the context
-
-[SEQ]
-
-<s1;s2,c> => c'' <= <s1,c> => c' <s2,c'> => c''
-
-[SIf]
-
-<if e s1 s2,c> => pop(c''') <= <e,c> => <true,c'> push(c') <s1,c''> => c'''
-
--<if e s1 s2,c> => pop(c''') <= <e,c> => <false,c'> push(c') <s2,c''> => c'''
++typing rules
++++++++++++++
++[EFunc]
--[SWhile]
++(t is used for types, T is the context, and + is used for in)
--<while e s,c> => c' => <e,c> => <false,c'>
++T+ i (es) : t <= i(ts):t in T & T+ es:ts
--<while e s,c> => pop(c''') => <e,c> => <true,c'> push(c') => c'' <s,c''> => c'''
++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
++[SReturn]
--[SDecl]
++T+ return e <= e:t & ret(t) in T
--<i := e,c> => c'[i->v] <= <e,c> => <v,c'>
++return typechecks if e returns the same type as the current context
--Adds i with value v to the current scope in the context
++[Func]
--[SDeclD]
++T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t
--<int i,c> => c[i->0]
--<bool i,c> => c[i->false]
++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
--Adds i with default value in the current scope
++semantic rules
++++++++++++++
--[SNoop]
--<SNoop,c> => c
++(v is used for values, e for expressions, s for statements, c is the context)
--SNoops does nothing so the same context is returned
--[SPrint]
--<e,c> => c'' <= <e,c> => <v,c'> <IO v,c'> => c''