X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=documentation;h=d649bbaedbe29fe03f586ac9699b30c70b0f4348;hb=98e238b8dd8c07705ab9681ff07c85e10eda9397;hp=cb693df417c88f4430589c5ac0de2ce533360c91;hpb=67721d82f79e56db9c728aed76a3ad9dcca005c2;p=proglang.git diff --git a/documentation b/documentation index cb693df..d649bba 100644 --- a/documentation +++ b/documentation @@ -1,77 +1,85 @@ ####### 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 +++++++++++++ +(t is little tau, T is large tau, E is 'in', and + is that other symbol) +[Eq, Neq] +e:bool <= e1:t & e2:t +where e is e1 Eq e2. +[Plus, Minus, Times, Div] +e:int <= e1:int & e2:int +where e is e1 Plus e2. +[Lt, ELt, Gt, EGt] +e:bool <= e1:int & e2:int +where e is e1 Lt e2. -examples: +[Assignment] -fib ---- -int n1 = 0; -int n2 = 1; -int n = readInt; +T+ i := e:t <= i:t E T & T+ e:t +where the assignment is identifier i = expression e. -while(n-- > 0){ - int temp = n1+n2; - n1 = n2; - n2 = temp; -} -print n2; +[ExpT] -tests while, decr and assignment. +u,e:t <= e:t & u:t +where the expression is type u expression e. +[ENeg] -if --- -if (readBool) { - if (readInt < 0) - print true; - else - print false; -} +e:int <= e:int -tests if and if/else. +[ENot] +e:bool <= e:bool + + +[SExp, SBlock] + +S:NoType <= e:t + + +[SIf] + +T+ if e then s1 else s2 <= T+ e:bool & T+ s1 & T+ s2 + + +[SWhile] + +T+ while e do s <= T+ e:bool & T+ s + + +[SDecl] + +T+ i:t => T', i:t <= i!ET & e:t & u:t + +(Type u Ident i = Exp e) -sum ---- -int n; -int sum = 0; -while ((n = readInt) != -1) sum = sum + n; -print sum; -var ---- -int a = 3; -int b = a - 5; -int c = a + b*7; -bool d = a == b; -tests simple variable operations. \ No newline at end of file