X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=documentation;h=c3ac4e08ba815c574432d3e2f0905cf120a460e1;hb=9625a8a7eb7aebeb161ca15cf66cff5699f89103;hp=70bd0c818b7f8c298ca3658a67729c6413db122b;hpb=ef4659dbfa5051372cf067f8c0ed2bbe77146650;p=proglang.git diff --git a/documentation b/documentation index 70bd0c8..c3ac4e0 100644 --- a/documentation +++ b/documentation @@ -1,97 +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, post increase/decrease expressions (++, --) are supported. Assignments are allowed in expressions, but they are only allowed on the right side of arithmetic/comparision operators if they are put inside parenthesis +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. -data types: -integers and booleans. +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. -comments: -// and /* */ comments are allowed. -(For compilation to work the Bool type in Abssyntax has to be removed so the internal haskell type is used) - -shift/reduce conflicts: - -if with else: 1 conflict -An if statement before the else could be reduced to an if statement lacking the else, but the correct thing is to shift it onto the stack. +typing rules +++++++++++++ +(v is used for values, e for expressions, s for statements, c is the context) -typing rules -++++++++++++ +[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt] + => <= => => v is the result of using operator o on v1 and v2 -(t is little tau, T is large tau, E is 'in', and + is that other symbol) +[Assignment] + => c'[i -> v] <= => -[Eq, Neq] +Assign the value v to i in the first scope i is found in. -e:bool <= e1:t & e2:t -where e is e1 Eq e2. +[ENeg] + => <-v,c'> <= => -[Plus, Minus, Times, Div] -e:int <= e1:int & e2:int -where e is e1 Plus e2. +[ENot] + => <= => -[Lt, ELt, Gt, EGt] +[EVar] -e:bool <= e1:int & e2:int -where e is e1 Lt e2. + => +[EInt] -[Assignment] + => -T+ i := e:t <= i:t E T & T+ e:t -where the assignment is identifier i = expression e. +[EBool] + => -[ExpT] +[EReadI,EReadB] -u,e:t <= e:t & u:t -where the expression is type u expression e. + => <= => +[EPost] -[ENeg] + => v']> <= c(i) => v, v±1 => v' -e:int <= e:int +Look up the variable, add/subtract 1 from the value then return the old value and context with modified value +[SExp] -[ENot] + => c' <= => -e:bool <= e:bool +[SBlock] + => c''' <= push(c) => c' => c'' pop(c'') => c''' -[SExp, SBlock] +Push a new scope onto the context, execute the statements in this context and the pop the scope from the context -S:NoType <= e:t +[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''