X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=documentation;h=f46afb702549b5b0a7a530b699a49ea20fb2c5d1;hb=bb79f91257da50013a4175c7c57973a6570eb3a1;hp=bbb604f08eb7bb7225e8219460a812238e158726;hpb=99548e772decde168669179c0da03109a9df5356;p=proglang.git diff --git a/documentation b/documentation index bbb604f..f46afb7 100644 --- a/documentation +++ b/documentation @@ -1,7 +1,18 @@ ####### DOCUMENTATIATOIAITAT ION ######## +Usage: + +./CompInt [-c] [file] + +-c : Compile [file], interprets if it isn't specified + +if no arguments are specified then the file is interpreted Files: +Interpret.hs: Handles the interpretation of a program + +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. @@ -9,135 +20,36 @@ 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. +Additions which comes from the extension: + typing rules ++++++++++++ +[EFunc] (t is used for types, T is the context, and + is used for in) +T+ i (es) : t <= i(ts):t in T & T+ es:ts -[Eq, NEq] - -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 - -The operators Lt/ELt/Gt/EGt return bool if both operands are ints - - -[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. - - -[ENeg] - -T+ ENeg e:int <= T+ e:int - -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 - -[EVar] - -T+ i:t <= i:t in T - -i has type t if i is defined in the context with type t. - -[EInt] +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 -T+ n:int +[SReturn] -n has type int +T+ return e <= e:t & ret(t) in T -[EBool] +return typechecks if e returns the same type as the current context -T+ b:bool +[Func] -b has type bool +T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t -[EReadI] +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+ n:int - -EReadI returns an int - -[EReadB] - -T+ b:bool - -EReadB returns a bool - -[EPost] - -T+ EPost i:int <= i:int in T - -EPost i is of type int if i is defined in T with type int. - -[SExp] - -T+ e <= T+ e:t - -[SBlock] - -T+ s;SBlock ss <= T+ s => T' , T'+ ss => T'' - -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' - - -[SIf] - -T+ if e then s1 else s2 <= T+ e:bool & T+ s1 & T+ s2 - -if e is of type bool and s1 and and s2 typechecks in the context T, then the same context is returned - - -[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 not in T & 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 not in T - -if i is not declared in the current scope, then i is added to the context with type t - -[SNoop] +semantic rules +++++++++++++ -T+ s -SNoops does nothing so the same context is returned +(v is used for values, e for expressions, s for statements, c is the context) -[SPrint] -T+ e <= T+ e:t -if e has type t then SPrint returns the same context