X-Git-Url: https://ruin.nu/git/index.pl?a=blobdiff_plain;f=documentation;h=fd4664dac04d54fd6b6dcd63704cf8532714b799;hb=4ab526ea4f2ad39b6797adbc9df0fd26ac571456;hp=d649bbaedbe29fe03f586ac9699b30c70b0f4348;hpb=2c2f90fca1005f6dedc69ee7f3d7c5072e5c123b;p=proglang.git diff --git a/documentation b/documentation index d649bba..fd4664d 100644 --- a/documentation +++ b/documentation @@ -9,77 +9,102 @@ 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. -typing rules +semantic rules ++++++++++++ -(t is little tau, T is large tau, E is 'in', and + is that other symbol) +(v is used for values, e for expressions, s for statements, c is the context) -[Eq, Neq] +[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt] -e:bool <= e1:t & e2:t -where e is e1 Eq e2. + => <= => => v is the result of using operator o on v1 and v2 -[Plus, Minus, Times, Div] +[Assignment] -e:int <= e1:int & e2:int -where e is e1 Plus e2. + => c'[i -> v] <= => +Assign the value v to i in the first scope i is found in. -[Lt, ELt, Gt, EGt] +[ENeg] -e:bool <= e1:int & e2:int -where e is e1 Lt e2. + => <-v,c'> <= => -[Assignment] +[ENot] -T+ i := e:t <= i:t E T & T+ e:t -where the assignment is identifier i = expression e. + => <= => +[EVar] -[ExpT] + => -u,e:t <= e:t & u:t -where the expression is type u expression e. +[EInt] + => -[ENeg] +[EBool] -e:int <= e:int + => +[EReadI,EReadB] -[ENot] + => <= => + +[EPost] -e:bool <= e:bool + => 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, SBlock] +[SExp] -S:NoType <= e:t + => 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] -T+ if e then s1 else s2 <= T+ e:bool & T+ s1 & T+ s2 + => pop(c''') <= => push(c') => c''' + + => pop(c''') <= => push(c') => c''' [SWhile] -T+ while e do s <= T+ e:bool & T+ s + => c' => => + + => pop(c''') => => push(c') => c'' => c''' [SDecl] -T+ i:t => T', i:t <= i!ET & e:t & u:t + => c'[i->v] <= => + +Adds i with value v to the current scope in the context -(Type u Ident i = Exp e) +[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''