]> ruin.nu Git - proglang.git/blobdiff - documentation
minor change
[proglang.git] / documentation
index 269e93139c744f83508a076206088f76e7634b81..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.
+Usage:
 
-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.
+./CompInt [-c] [file]
 
+-c : Compile [file], interprets if it isn't specified
 
-typing rules
-++++++++++++
+if no arguments are specified then the file is interpreted
 
+Files:
+Interpret.hs: Handles the interpretation of a program
 
-(t is little tau, T is large tau, E is 'in', and + is that other symbol)
+Compile.hs: Compiles the program into a c program
 
+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.
 
-[Eq, Neq]
+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.
 
-e:bool  <=  e1:t  &  e2:t
-where e is e1 Eq e2.
 
+Additions which comes from the extension:
 
-[Plus, Minus, Times, Div]
+typing rules
+++++++++++++
 
-e:int  <=  e1:int  &  e2:int
-where e is e1 Plus e2.
+(t is used for types, T is the context, and + is used for in)
 
+[EFunc]
 
-[Lt, ELt, Gt, EGt]
+T+ i (es) : t <= i(ts):t in T & T+ es:ts 
 
-e:bool  <=  e1:int  &  e2:int
-where e is e1 Lt e2.
+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]
 
-[Assignment]
+T+ return e <= e:t & ret(t) in T
 
-T+ i := e:t  <=  i:t E T  &  T+ e:t
-where the assignment is identifier i = expression e.
+return typechecks if e returns the same type as the current context
 
+[Func]
 
-[ExpT]
+T+ t i (ds) => T' <= ds:ts & T,i(ts):t => T'
 
-u,e:t  <=  e:t  &  u:t
-where the expression is type u expression e.
+Adds the function with parameter types and returntype to the context
 
+T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t
 
-[ENeg]
+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
 
-e:int  <=  e:int
+[Program]
 
+T+ fs ss <= T+,fs => T' && T'+ fs && T'+ ss
 
-[ENot]
+The program typechecks if all the functions and all the statements typechecks in the context with all functions added to it.
 
-e:bool  <=  e:bool
+semantic rules
+++++++++++++
 
+(v is used for values, e for expressions, s for statements, c is the context)
 
-[SExp, SBlock]
+[EFunc]
 
-S:NoType  <=  e:t
+<i (es), c> => <o'''(ret),o'>  <= <es,c> => <vs,c'>, c(i) => <ds,ss>, c'[clearVars,ds->vs] => c'' <ss,o''> => o'''
 
+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.
 
-[SIf]
 
-T+ if e then s1 else s2  <=  T+ e:bool  &  T+ s1  &  T+ s2
+[SReturn]
 
+<return e,c> => c'[ret->v] <= <e,c> => <v,c'>
 
-[SWhile]
+Evaluate the expression, add the value as return value to the state and stop the execution of the state
 
-T+ while e do s  <=  T+ e:bool  &  T+ s
+[Func]
 
+<t i (ds) ss, c> => c[i-><ds,ss>]
 
-[SDecl]
+Adds the function i with parameters ds and body ss to the context
 
-T+ i:t => T', i:t  <=  i!ET  &  e:t  &  u:t
+[Program]
 
-(Type u Ident i = Exp e)
+<fs ss, c> => c'' <= c[fs] => c', <ss,c'> => c''
 
+Add all the function to the context and execute the statements in this context
 
+[SEQ]
 
+<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]
 
+<while e s,c> => c''' => <e,c> => <true,c'> push(c') => c'' <s,c''> => c''', c'''(ret)
 
+If the context returned by the body contains a return-value, return this context and don't try to run the loop again.