]> ruin.nu Git - proglang.git/blobdiff - documentation
updating documentation
[proglang.git] / documentation
index bbb604f08eb7bb7225e8219460a812238e158726..47008eefba987fb88613cf46094072b64c289764 100644 (file)
 ####### DOCUMENTATIATOIAITAT ION ########
 
+Usage:
 
-Files:
-Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
+./CompInt [-c] [file]
 
-Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
+-c : Compile [file], interprets if it isn't specified
 
-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
-++++++++++++
-
-
-(t is used for types, T is the context, and + is used for in)
+if no arguments are specified then the file is interpreted
 
+Files:
+Interpret.hs: Handles the interpretation of a program
 
-[Eq, NEq]
+Compile.hs: Compiles the program into a c program
 
-T+ e1 Eq e2:bool  <=  T+ e1:t  &  T+ e2:t
+Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
 
-If e1 and e2 are of the same type, then Eq or NEq return bool
+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.
 
-[Plus, Minus, Times, Div]
 
-T+ e1 Plus e2:int  <=  T+ e1:int  &  T+ e2:int
+semantic rules
+++++++++++++
 
-The operators Plus/Minus/Times/Div return int if both operands are ints
 
+(v is used for values, e for expressions, s for statements, c is the context)
 
-[Lt, ELt, Gt, EGt]
 
-T+ e1 Lt e2:bool  <=  T+ e1:int  &  T+ e2:int
+[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
 
-The operators Lt/ELt/Gt/EGt return bool if both operands are ints
+<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]
 
-T+ i := e:t  <=  i:t in T  &  T+ e:t
-
-The assignemnt of e to i returns type t if both i and e have type t.
+<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]
 
-T+ ENeg e:int  <=  T+ e:int
+<e,c> => <-v,c'> <= <e,c> => <v,c'>
 
-ENeg e returns int if e is of type int
 
 [ENot]
 
-T+ ENot e:bool  <=  e:bool
-
-ENot e returns bool if e is of type bool
+<e,c> => <not v,c'> <= <e,c> => <v,c'>
 
 [EVar]
 
-T+ i:t <= i:t in T
-
-i has type t if i is defined in the context with type t.
+<i,c> => <c(i),c>
 
 [EInt]
 
-T+ n:int
-
-n has type int
+<n,c> => <n,c>
 
 [EBool]
 
-T+ b:bool
-
-b has type bool
-
-[EReadI]
+<b,c> => <b,c>
 
-T+ n:int
+[EReadI,EReadB]
 
-EReadI returns an int
-
-[EReadB]
-
-T+ b:bool
-
-EReadB returns a bool
+<c> => <v,c'> <= <IO,c> => <v,c'>
 
 [EPost]
 
-T+ EPost i:int <= i:int in T
+<i,c> => <v,c[i->v']> <= c(i) => v, v±1 => v'
 
-EPost i is of type int if i is defined in T with type int.
+Look up the variable, add/subtract 1 from the value then return the old value and context with modified value
 
 [SExp]
 
-T+ e   <=  T+ e:t
+<e,c> => c' <= <e,c> => <v,c'>
 
 [SBlock]
 
-T+ s;SBlock ss <= T+ s => T' , T'+ ss => T''
+<SBlock s,c> => c'''  <= push(c) => c' <s,c'> => c'' pop(c'') => c'''
 
-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' 
+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]
 
-T+ if e then s1 else s2  <=  T+ e:bool  &  T+ s1  &  T+ s2
+<if e s1 s2,c> => pop(c''') <= <e,c> => <true,c'> push(c') <s1,c''> => c'''
 
-if e is of type bool and s1 and and s2 typechecks in the context T, then the same context is returned
+<if e s1 s2,c> => pop(c''') <= <e,c> => <false,c'> push(c') <s2,c''> => c'''
 
 
 [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
+<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]
 
-T+ t i = e => T,i:t  <=  i not in T  &  e:t 
+<i := e,c> => c'[i->v] <= <e,c> => <v,c'>
 
-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.
+Adds i with value v to the current scope in the context
 
 [SDeclD]
 
-T+ t i => T,i:t  <=  i not in T
+<int i,c> => c[i->0]
+<bool i,c> => c[i->false]
 
-if i is not declared in the current scope, then i is added to the context with type t
+Adds i with default value in the current scope
 
 [SNoop]
 
-T+ s
+<SNoop,c> => c
 
 SNoops does nothing so the same context is returned
 
 [SPrint]
 
-T+ e <= T+ e:t
-
-if e has type t then SPrint returns the same context
+<e,c> => c'' <= <e,c> => <v,c'> <IO v,c'>  => c''