]> ruin.nu Git - proglang.git/blobdiff - documentation
compiler seems to be working
[proglang.git] / documentation
index c77568b12f0b8d6434f10e1ef99c82d6a6d751f9..c3ac4e08ba815c574432d3e2f0905cf120a460e1 100644 (file)
 ####### 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.
+Files:
+Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
 
-data types:
-integers and booleans.
+Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
 
-comments:
-// and /* */ comments are allowed.
+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.
 
-(For compilation to work the Bool type in Abssyntax has to be removed so the internal haskell type is used)
 
-shift/reduce conflicts:
+typing rules
+++++++++++++
 
-18 conflicts in total.
 
-1) Exp1 followed by (<,<=,>,>=,==,!=,+,-) 8 conflicts:
-In these cases the Exp1 could've been reduced to Exp, but happy does the correct thing and shifts the operator token onto the stack, since Exp followed by these operators doesn't match any rules.
+(v is used for values, e for expressions, s for statements, c is the context)
 
-2) Exp2 followed by (*,/) 4 conflicts:
-In two cases the Exp2 expression could be reduced to Exp1, but this wouldn't match the rules for these operators, so shifting is the correct action.
 
-In two other cases the Exp2 in front of these operators can be reduced to addition and subtraction expressions, which would destroy operator priority, so shifting is correct here.
+[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
 
-3) Exp1 followed by (+,-) 2 conflicts:
-In both these cases Exp1 could be reduced together with another Exp1 and a comparative operator to an Exp, but just as in the above case this would be very bad for operator priority, so shifting is right here.
+<e1 o e2,c> => <v,c''> <= <e1,c> => <v1,c'>  <e2,c'> => <v2,c''> v is the result of using operator o on v1 and v2
 
-4) 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.
 
-5) if/ifelse/while followed by (;): 3 conflicts
-Here we have redundant semicolons, these could all be reduced to individual statements without the ';'. Such a reduction wouldn't cause any harm, but neither does the shifting, it's an ok choice.
+[Assignment]
+
+<i := e,c> => c'[i -> v] <= <e,c> => <v,c'>
+
+Assign the value v to i in the first scope i is found in.
+
+[ENeg]
+
+<e,c> => <-v,c'> <= <e,c> => <v,c'>
+
+
+[ENot]
+
+<e,c> => <not v,c'> <= <e,c> => <v,c'>
+
+[EVar]
+
+<i,c> => <c(i),c>
+
+[EInt]
+
+<n,c> => <n,c>
+
+[EBool]
+
+<b,c> => <b,c>
+
+[EReadI,EReadB]
+
+<c> => <v,c'> <= <IO,c> => <v,c'>
+
+[EPost]
+
+<i,c> => <v,c[i->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]
+
+<e,c> => c' <= <e,c> => <v,c'>
+
+[SBlock]
+
+<SBlock s,c> => c'''  <= push(c) => c' <s,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]
+
+<s1;s2,c> => c'' <= <s1,c> => c' <s2,c'> => c''
+
+[SIf]
+
+<if e s1 s2,c> => pop(c''') <= <e,c> => <true,c'> push(c') <s1,c''> => c'''
+
+<if e s1 s2,c> => pop(c''') <= <e,c> => <false,c'> push(c') <s2,c''> => c'''
+
+
+[SWhile]
+
+<while e s,c> => c' => <e,c> => <false,c'>
+
+<while e s,c> => pop(c''') => <e,c> => <true,c'> push(c') => c'' <s,c''> => c'''
+
+
+[SDecl]
+
+<i := e,c> => c'[i->v] <= <e,c> => <v,c'>
+
+Adds i with value v to the current scope in the context
+
+[SDeclD]
+
+<int i,c> => c[i->0]
+<bool i,c> => c[i->false]
+
+Adds i with default value in the current scope
+
+[SNoop]
+
+<SNoop,c> => c
+
+SNoops does nothing so the same context is returned
+
+[SPrint]
+
+<e,c> => c'' <= <e,c> => <v,c'> <IO v,c'>  => c''