]> ruin.nu Git - proglang.git/blobdiff - documentation
minor change
[proglang.git] / documentation
index c3ac4e08ba815c574432d3e2f0905cf120a460e1..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
-++++++++++++
-
-
-(v is used for values, e for expressions, s for statements, c is the context)
 
+Usage:
 
-[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
+./CompInt [-c] [file]
 
-<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
+-c : Compile [file], interprets if it isn't specified
 
+if no arguments are specified then the file is interpreted
 
-[Assignment]
-
-<i := e,c> => c'[i -> v] <= <e,c> => <v,c'>
+Files:
+Interpret.hs: Handles the interpretation of a program
 
-Assign the value v to i in the first scope i is found in.
+Compile.hs: Compiles the program into a c program
 
-[ENeg]
+Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
 
-<e,c> => <-v,c'> <= <e,c> => <v,c'>
+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.
 
-[ENot]
 
-<e,c> => <not v,c'> <= <e,c> => <v,c'>
+Additions which comes from the extension:
 
-[EVar]
+typing rules
+++++++++++++
 
-<i,c> => <c(i),c>
+(t is used for types, T is the context, and + is used for in)
 
-[EInt]
+[EFunc]
 
-<n,c> => <n,c>
+T+ i (es) : t <= i(ts):t in T & T+ es:ts 
 
-[EBool]
+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
 
-<b,c> => <b,c>
+[SReturn]
 
-[EReadI,EReadB]
+T+ return e <= e:t & ret(t) in T
 
-<c> => <v,c'> <= <IO,c> => <v,c'>
+return typechecks if e returns the same type as the current context
 
-[EPost]
+[Func]
 
-<i,c> => <v,c[i->v']> <= c(i) => v, v±1 => v'
+T+ t i (ds) => T' <= ds:ts & T,i(ts):t => T'
 
-Look up the variable, add/subtract 1 from the value then return the old value and context with modified value
+Adds the function with parameter types and returntype to the context
 
-[SExp]
+T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t
 
-<e,c> => c' <= <e,c> => <v,c'>
+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
 
-[SBlock]
+[Program]
 
-<SBlock s,c> => c'''  <= push(c) => c' <s,c'> => c'' pop(c'') => c'''
+T+ fs ss <= T+,fs => T' && T'+ fs && T'+ ss
 
-Push a new scope onto the context, execute the statements in this context and the pop the scope from the context
+The program typechecks if all the functions and all the statements typechecks in the context with all functions added to it.
 
-[SEQ]
+semantic rules
+++++++++++++
 
-<s1;s2,c> => c'' <= <s1,c> => c' <s2,c'> => c''
+(v is used for values, e for expressions, s for statements, c is the context)
 
-[SIf]
+[EFunc]
 
-<if e s1 s2,c> => pop(c''') <= <e,c> => <true,c'> push(c') <s1,c''> => c'''
+<i (es), c> => <o'''(ret),o'>  <= <es,c> => <vs,c'>, c(i) => <ds,ss>, c'[clearVars,ds->vs] => c'' <ss,o''> => o'''
 
-<if e s1 s2,c> => pop(c''') <= <e,c> => <false,c'> push(c') <s2,c''> => 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.
 
 
-[SWhile]
+[SReturn]
 
-<while e s,c> => c' => <e,c> => <false,c'>
+<return e,c> => c'[ret->v] <= <e,c> => <v,c'>
 
-<while e s,c> => pop(c''') => <e,c> => <true,c'> push(c') => c'' <s,c''> => c'''
+Evaluate the expression, add the value as return value to the state and stop the execution of the state
 
+[Func]
 
-[SDecl]
+<t i (ds) ss, c> => c[i-><ds,ss>]
 
-<i := e,c> => c'[i->v] <= <e,c> => <v,c'>
+Adds the function i with parameters ds and body ss to the context
 
-Adds i with value v to the current scope in the context
+[Program]
 
-[SDeclD]
+<fs ss, c> => c'' <= c[fs] => c', <ss,c'> => c''
 
-<int i,c> => c[i->0]
-<bool i,c> => c[i->false]
+Add all the function to the context and execute the statements in this context
 
-Adds i with default value in the current scope
+[SEQ]
 
-[SNoop]
+<s1;s2,c> => c' <= <s1,c> => c', c'(ret)
 
-<SNoop,c> => c
+If the context returned by s1 contains a return-value, return this context without executing the next statement.
 
-SNoops does nothing so the same context is returned
+[SWhile]
 
-[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.