]> ruin.nu Git - proglang.git/blobdiff - documentation
minor change
[proglang.git] / documentation
index 47008eefba987fb88613cf46094072b64c289764..196220aa96faa3596dea5c7a9fd1ebf33d76b275 100644 (file)
@@ -1,5 +1,8 @@
 ####### DOCUMENTATIATOIAITAT ION ########
 
+Functions has been added, with c style syntax.
+
+
 Usage:
 
 ./CompInt [-c] [file]
@@ -20,102 +23,79 @@ Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar an
 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.
 
 
-semantic rules
+Additions which comes from the extension:
+
+typing rules
 ++++++++++++
 
+(t is used for types, T is the context, and + is used for in)
 
-(v is used for values, e for expressions, s for statements, c is the context)
+[EFunc]
 
+T+ i (es) : t <= i(ts):t in T & T+ es:ts 
 
-[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
+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
 
-<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
+[SReturn]
 
+T+ return e <= e:t & ret(t) in T
 
-[Assignment]
+return typechecks if e returns the same type as the current context
 
-<i := e,c> => c'[i -> v] <= <e,c> => <v,c'>
+[Func]
 
-Assign the value v to i in the first scope i is found in.
+T+ t i (ds) => T' <= ds:ts & T,i(ts):t => T'
 
-[ENeg]
+Adds the function with parameter types and returntype to the context
 
-<e,c> => <-v,c'> <= <e,c> => <v,c'>
+T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t
 
+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
 
-[ENot]
+[Program]
 
-<e,c> => <not v,c'> <= <e,c> => <v,c'>
+T+ fs ss <= T+,fs => T' && T'+ fs && T'+ ss
 
-[EVar]
+The program typechecks if all the functions and all the statements typechecks in the context with all functions added to it.
 
-<i,c> => <c(i),c>
+semantic rules
+++++++++++++
 
-[EInt]
+(v is used for values, e for expressions, s for statements, c is the context)
 
-<n,c> => <n,c>
+[EFunc]
 
-[EBool]
+<i (es), c> => <o'''(ret),o'>  <= <es,c> => <vs,c'>, c(i) => <ds,ss>, c'[clearVars,ds->vs] => c'' <ss,o''> => o'''
 
-<b,c> => <b,c>
+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.
 
-[EReadI,EReadB]
 
-<c> => <v,c'> <= <IO,c> => <v,c'>
+[SReturn]
 
-[EPost]
+<return e,c> => c'[ret->v] <= <e,c> => <v,c'>
 
-<i,c> => <v,c[i->v']> <= c(i) => v, v±1 => v'
+Evaluate the expression, add the value as return value to the state and stop the execution of the state
 
-Look up the variable, add/subtract 1 from the value then return the old value and context with modified value
+[Func]
 
-[SExp]
+<t i (ds) ss, c> => c[i-><ds,ss>]
 
-<e,c> => c' <= <e,c> => <v,c'>
+Adds the function i with parameters ds and body ss to the context
 
-[SBlock]
+[Program]
 
-<SBlock s,c> => c'''  <= push(c) => c' <s,c'> => c'' pop(c'') => c'''
+<fs ss, c> => c'' <= c[fs] => c', <ss,c'> => c''
 
-Push a new scope onto the context, execute the statements in this context and the pop the scope from the context
+Add all the function to the context and execute the statements in this 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'''
+<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> => <false,c'>
-
-<while e s,c> => pop(c''') => <e,c> => <true,c'> push(c') => c'' <s,c''> => c'''
-
-
-[SDecl]
-
-<i := e,c> => c'[i->v] <= <e,c> => <v,c'>
-
-Adds i with value v to the current scope in the context
-
-[SDeclD]
-
-<int i,c> => c[i->0]
-<bool i,c> => c[i->false]
-
-Adds i with default value in the current scope
-
-[SNoop]
-
-<SNoop,c> => c
-
-SNoops does nothing so the same context is returned
-
-[SPrint]
+<while e s,c> => c''' => <e,c> => <true,c'> push(c') => c'' <s,c''> => c''', c'''(ret)
 
-<e,c> => c'' <= <e,c> => <v,c'> <IO v,c'>  => c''
+If the context returned by the body contains a return-value, return this context and don't try to run the loop again.