]> ruin.nu Git - proglang.git/blobdiff - documentation
minor change
[proglang.git] / documentation
index c77568b12f0b8d6434f10e1ef99c82d6a6d751f9..196220aa96faa3596dea5c7a9fd1ebf33d76b275 100644 (file)
 ####### DOCUMENTATIATOIAITAT ION ########
 
+Functions has been added, with c style syntax.
 
-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.
 
-data types:
-integers and booleans.
+Usage:
 
-comments:
-// and /* */ comments are allowed.
+./CompInt [-c] [file]
 
-(For compilation to work the Bool type in Abssyntax has to be removed so the internal haskell type is used)
+-c : Compile [file], interprets if it isn't specified
 
-shift/reduce conflicts:
+if no arguments are specified then the file is interpreted
 
-18 conflicts in total.
+Files:
+Interpret.hs: Handles the interpretation of a 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.
+Compile.hs: Compiles the program into a c program
 
-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.
+Typechecker.hs: Simple modification of the bnfc-generated Testsyntax which calls the type-checking functions.
 
-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.
+Typecheck.hs: Contains the type-checking functions typeCheckExp, typeCheckVar and typeCheckStm and some utility functions, responsible for the entire type-checking process.
 
-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.
+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.
 
-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.
+Additions which comes from the extension:
+
+typing rules
+++++++++++++
+
+(t is used for types, T is the context, and + is used for in)
+
+[EFunc]
+
+T+ i (es) : t <= i(ts):t in T & T+ es:ts 
+
+The functioncall of i returns t if i is in the context with returntype t and the types of the argument expressions matches those in the parameter list
+
+[SReturn]
+
+T+ return e <= e:t & ret(t) in T
+
+return typechecks if e returns the same type as the current context
+
+[Func]
+
+T+ t i (ds) => T' <= ds:ts & T,i(ts):t => T'
+
+Adds the function with parameter types and returntype to the context
+
+T+ t i (ds) ss <= T,novariables,ret(t),ds => T' & T'+ss & last(ss) => return:t
+
+the function i typechecks if the body typechecks in the context where all other variables has been removed and the return type and paramters has been added and that the last statement is a return with the right type
+
+[Program]
+
+T+ fs ss <= T+,fs => T' && T'+ fs && T'+ ss
+
+The program typechecks if all the functions and all the statements typechecks in the context with all functions added to it.
+
+semantic rules
+++++++++++++
+
+(v is used for values, e for expressions, s for statements, c is the context)
+
+[EFunc]
+
+<i (es), c> => <o'''(ret),o'>  <= <es,c> => <vs,c'>, c(i) => <ds,ss>, c'[clearVars,ds->vs] => c'' <ss,o''> => o'''
+
+Evaluate the arguments in order, find function definition, remove the old variables and add values from the arguments to the parameters. execute the body until retun. Return the value from the return state and the state from the argument expressions.
+
+
+[SReturn]
+
+<return e,c> => c'[ret->v] <= <e,c> => <v,c'>
+
+Evaluate the expression, add the value as return value to the state and stop the execution of the state
+
+[Func]
+
+<t i (ds) ss, c> => c[i-><ds,ss>]
+
+Adds the function i with parameters ds and body ss to the context
+
+[Program]
+
+<fs ss, c> => c'' <= c[fs] => c', <ss,c'> => c''
+
+Add all the function to the context and execute the statements in this context
+
+[SEQ]
+
+<s1;s2,c> => c' <= <s1,c> => c', c'(ret)
+
+If the context returned by s1 contains a return-value, return this context without executing the next statement.
+
+[SWhile]
+
+<while e s,c> => c''' => <e,c> => <true,c'> push(c') => c'' <s,c''> => c''', c'''(ret)
+
+If the context returned by the body contains a return-value, return this context and don't try to run the loop again.