X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=documentation;h=c3ac4e08ba815c574432d3e2f0905cf120a460e1;hb=04f0a9566794cf761b7bcf83190051a400ec3653;hp=cf26d0aafadec73cf148288555cd48e3ee6ea6ef;hpb=5f2040d19e69f864edcc7f2e2d27ea9bd298d26a;p=proglang.git diff --git a/documentation b/documentation index cf26d0a..c3ac4e0 100644 --- a/documentation +++ b/documentation @@ -1,11 +1,110 @@ ####### DOCUMENTATIATOIAITAT ION ######## -a simple c-like language with support for if/else-statements, while-loops and the standard arithmetic (+, -, /, *) and comparison expressions (<, >, <=, >=, ==, !=). also, increase/decrease expressions (++, --) are supported. +Files: +Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions. -data types: -integers and booleans. +Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process. -comments: -// and /* */ comments are allowed. +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) + + +[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt] + + => <= => => v is the result of using operator o on v1 and v2 + + +[Assignment] + + => c'[i -> v] <= => + +Assign the value v to i in the first scope i is found in. + +[ENeg] + + => <-v,c'> <= => + + +[ENot] + + => <= => + +[EVar] + + => + +[EInt] + + => + +[EBool] + + => + +[EReadI,EReadB] + + => <= => + +[EPost] + + => v']> <= c(i) => v, v±1 => v' + +Look up the variable, add/subtract 1 from the value then return the old value and context with modified value + +[SExp] + + => c' <= => + +[SBlock] + + => c''' <= push(c) => c' => c'' pop(c'') => c''' + +Push a new scope onto the context, execute the statements in this context and the pop the scope from the context + +[SEQ] + + => c'' <= => c' => c'' + +[SIf] + + => pop(c''') <= => push(c') => c''' + + => pop(c''') <= => push(c') => c''' + + +[SWhile] + + => c' => => + + => pop(c''') => => push(c') => c'' => c''' + + +[SDecl] + + => c'[i->v] <= => + +Adds i with value v to the current scope in the context + +[SDeclD] + + => c[i->0] + => c[i->false] + +Adds i with default value in the current scope + +[SNoop] + + => c + +SNoops does nothing so the same context is returned + +[SPrint] + + => c'' <= => => c''