X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=documentation;h=c3ac4e08ba815c574432d3e2f0905cf120a460e1;hb=97719af3b544b9fae80e886bf6a49c51b4a320a9;hp=cb693df417c88f4430589c5ac0de2ce533360c91;hpb=67721d82f79e56db9c728aed76a3ad9dcca005c2;p=proglang.git diff --git a/documentation b/documentation index cb693df..c3ac4e0 100644 --- a/documentation +++ b/documentation @@ -1,77 +1,110 @@ ####### DOCUMENTATIATOIAITAT ION ######## +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. -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. +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. -data types: -integers and booleans. -comments: -// and /* */ comments are allowed. +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'> <= => -examples: +[ENot] -fib ---- -int n1 = 0; -int n2 = 1; -int n = readInt; + => <= => -while(n-- > 0){ - int temp = n1+n2; - n1 = n2; - n2 = temp; -} -print n2; +[EVar] + => -tests while, decr and assignment. +[EInt] + => +[EBool] -if --- -if (readBool) { - if (readInt < 0) - print true; - else - print false; -} + => +[EReadI,EReadB] -tests if and if/else. + => <= => +[EPost] + => v']> <= c(i) => v, v±1 => v' -sum ---- -int n; -int sum = 0; -while ((n = readInt) != -1) sum = sum + n; -print sum; +Look up the variable, add/subtract 1 from the value then return the old value and context with modified value +[SExp] + => c' <= => +[SBlock] -var ---- -int a = 3; -int b = a - 5; -int c = a + b*7; -bool d = a == b; + => c''' <= push(c) => c' => c'' pop(c'') => c''' -tests simple variable operations. \ No newline at end of file +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''