X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=documentation;h=bbb604f08eb7bb7225e8219460a812238e158726;hp=70bd0c818b7f8c298ca3658a67729c6413db122b;hb=d553df8dfdffca78342d6fae142ceded9cd64415;hpb=ef4659dbfa5051372cf067f8c0ed2bbe77146650 diff --git a/documentation b/documentation index 70bd0c8..bbb604f 100644 --- a/documentation +++ b/documentation @@ -1,97 +1,143 @@ ####### 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) +typing rules +++++++++++++ -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. +(t is used for types, T is the context, and + is used for in) +[Eq, NEq] +T+ e1 Eq e2:bool <= T+ e1:t & T+ e2:t -typing rules -++++++++++++ +If e1 and e2 are of the same type, then Eq or NEq return bool -(t is little tau, T is large tau, E is 'in', and + is that other symbol) +[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 -[Eq, Neq] -e:bool <= e1:t & e2:t -where e is e1 Eq e2. +[Lt, ELt, Gt, EGt] +T+ e1 Lt e2:bool <= T+ e1:int & T+ e2:int -[Plus, Minus, Times, Div] +The operators Lt/ELt/Gt/EGt return bool if both operands are ints -e:int <= e1:int & e2:int -where e is e1 Plus e2. +[Assignment] -[Lt, ELt, Gt, EGt] +T+ i := e:t <= i:t in T & T+ e:t -e:bool <= e1:int & e2:int -where e is e1 Lt e2. +The assignemnt of e to i returns type t if both i and e have type t. -[Assignment] +[ENeg] -T+ i := e:t <= i:t E T & T+ e:t -where the assignment is identifier i = expression e. +T+ ENeg e:int <= T+ e:int +ENeg e returns int if e is of type int -[ExpT] +[ENot] -u,e:t <= e:t & u:t -where the expression is type u expression e. +T+ ENot e:bool <= e:bool +ENot e returns bool if e is of type bool -[ENeg] +[EVar] -e:int <= e:int +T+ i:t <= i:t in T +i has type t if i is defined in the context with type t. -[ENot] +[EInt] + +T+ n:int + +n has type int + +[EBool] -e:bool <= e:bool +T+ b:bool +b has type bool -[SExp, SBlock] +[EReadI] -S:NoType <= e:t +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+ i:t => T', i:t <= i!ET & e:t & u:t +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] -(Type u Ident i = Exp e) +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] +T+ s +SNoops does nothing so the same context is returned +[SPrint] +T+ e <= T+ e:t +if e has type t then SPrint returns the same context