]> ruin.nu Git - proglang.git/blobdiff - documentation
updating documentation
[proglang.git] / documentation
index 2d3fcac33546a4e9ed73608a54d47478f0c34ac7..47008eefba987fb88613cf46094072b64c289764 100644 (file)
 ####### DOCUMENTATIATOIAITAT ION ########
 
+Usage:
 
-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.
+./CompInt [-c] [file]
 
-data types:
-integers and booleans.
+-c : Compile [file], interprets if it isn't specified
 
-comments:
-// and /* */ comments are allowed.
+if no arguments are specified then the file is interpreted
 
-shift/reduce conflicts:
+Files:
+Interpret.hs: Handles the interpretation of a program
 
-30 conflicts in total.
+Compile.hs: Compiles the program into a c program
 
-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.
+Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
 
-2) Exp2 followed by (*,/) 6 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.
+Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
 
-In four 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.
+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.
 
-3) Exp1 followed by (+,-) 12 conflicts:
-In all 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.
 
-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.
+semantic rules
+++++++++++++
 
-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.
+
+(v is used for values, e for expressions, s for statements, c is the context)
+
+
+[Eq, NEq, Plus, Minus, Times, Div, Lt, ELt, Gt, EGt]
+
+<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
+
+
+[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''