]> ruin.nu Git - proglang.git/blobdiff - documentation
minor change
[proglang.git] / documentation
index 2d64044dfa366fbddc9bf43e007d8845df8e48ea..196220aa96faa3596dea5c7a9fd1ebf33d76b275 100644 (file)
 ####### DOCUMENTATIATOIAITAT ION ########
 
+Functions has been added, with c style syntax.
 
-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
-++++++++++++
 
+Usage:
 
-(t is little tau, T is large tau, E is 'in', and + is that other symbol)
+./CompInt [-c] [file]
 
+-c : Compile [file], interprets if it isn't specified
 
-[Eq, NEq]
+if no arguments are specified then the file is interpreted
 
-T+ e1 Eq e2:bool  <=  T+ e1:t  &  T+ e2:t
-
-If e1 and e2 are of the same type, then Eq or NEq return bool
-
-
-[Plus, Minus, Times, Div]
-
-T+ e1 Plus e2:int  <=  T+ e1:int  &  T+ e2:int
-
-The operators Plus/Minus/Times/Div return int if both operands are ints
-
-
-[Lt, ELt, Gt, EGt]
-
-T+ e1 Lt e2:bool  <=  T+ e1:int  &  T+ e2:int
+Files:
+Interpret.hs: Handles the interpretation of a program
 
-The operators Lt/ELt/Gt/EGt return bool if both operands are ints
+Compile.hs: Compiles the program into a c program
 
+Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
 
-[Assignment]
+Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
 
-T+ i := e:t  <=  i:t E T  &  T+ e:t
+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.
 
-The assignemnt of e to i returns type t if both i and e have type t.
 
+Additions which comes from the extension:
 
-[ENeg]
+typing rules
+++++++++++++
 
-T+ ENeg e:int  <=  T+ e:int
+(t is used for types, T is the context, and + is used for in)
 
-ENeg e returns int if e is of type int
+[EFunc]
 
-[ENot]
+T+ i (es) : t <= i(ts):t in T & T+ es:ts 
 
-T+ ENot e:bool  <=  e:bool
+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
 
-ENot e returns bool if e is of type bool
+[SReturn]
 
-[EVar]
+T+ return e <= e:t & ret(t) in T
 
-T+ i:t <= i:t E T
+return typechecks if e returns the same type as the current context
 
-i has type t if i is defined in the context with type t.
+[Func]
 
-[EInt]
+T+ t i (ds) => T' <= ds:ts & T,i(ts):t => T'
 
-T+ n:int
+Adds the function with parameter types and returntype to the context
 
-n has type int
+T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t
 
-[EBool]
+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
 
-T+ b:bool
+[Program]
 
-b has type bool
+T+ fs ss <= T+,fs => T' && T'+ fs && T'+ ss
 
-[EReadI]
+The program typechecks if all the functions and all the statements typechecks in the context with all functions added to it.
 
-T+ n:int
+semantic rules
+++++++++++++
 
-EReadI returns an int
+(v is used for values, e for expressions, s for statements, c is the context)
 
-[EReadB]
+[EFunc]
 
-T+ b:bool
+<i (es), c> => <o'''(ret),o'>  <= <es,c> => <vs,c'>, c(i) => <ds,ss>, c'[clearVars,ds->vs] => c'' <ss,o''> => o'''
 
-EReadB returns a bool
+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.
 
-[EPost]
 
-T+ EPost i:int <= i:int E T
+[SReturn]
 
-EPost i is of type int if i is defined in T with type int.
+<return e,c> => c'[ret->v] <= <e,c> => <v,c'>
 
-[SExp]
+Evaluate the expression, add the value as return value to the state and stop the execution of the state
 
-T+ e   <=  T+ e:t
+[Func]
 
-[SBlock]
+<t i (ds) ss, c> => c[i-><ds,ss>]
 
-T+ s;SBlock ss <= T+ s => T' , T'+ ss => T''
+Adds the function i with parameters ds and body ss to the context
 
-the first statment s, in the block, is typechecked in the context T and returns the context T', the rest of the block is then recursively typeckecked in the context T' 
+[Program]
 
+<fs ss, c> => c'' <= c[fs] => c', <ss,c'> => c''
 
-[SIf]
+Add all the function to the context and execute the statements in this context
 
-T+ if e then s1 else s2  <=  T+ e:bool  &  T+ s1  &  T+ s2
+[SEQ]
 
-if e is of type bool and s1 and and s2 typechecks in the context T, then the same context is returned
+<s1;s2,c> => c' <= <s1,c> => c', c'(ret)
 
+If the context returned by s1 contains a return-value, return this context without executing the next statement.
 
 [SWhile]
 
-T+ while e do s  <=  T+ e:bool  &  T+ s
-
-If e is of type bool and s typechecks in context T then the same context is returned
-
-
-
-[SDecl]
-
-T+ t i = e => T,i:t  <=  i!ET  &  e:t 
-
-if i and e are of the same type and i is not declared in the current scope then i is added with type t to the context.
-
-[SDeclD]
-
-T+ t i => T,i:t  <=  i!ET
-
-if i is not declared in the current scope, then i is added to the context with type t
-
-[SNoop]
-
-T+ s
-
-SNoops does nothing so the same context is returned
-
-[SPrint]
-
-T+ e <= T+ e:t
+<while e s,c> => c''' => <e,c> => <true,c'> push(c') => c'' <s,c''> => c''', c'''(ret)
 
-if e has type t then SPrint returns the same context
+If the context returned by the body contains a return-value, return this context and don't try to run the loop again.