]> ruin.nu Git - proglang.git/blobdiff - documentation
updating documentation
[proglang.git] / documentation
index cb693df417c88f4430589c5ac0de2ce533360c91..47008eefba987fb88613cf46094072b64c289764 100644 (file)
 ####### DOCUMENTATIATOIAITAT ION ########
 
+Usage:
 
+./CompInt [-c] [file]
 
+-c : Compile [file], interprets if it isn't specified
 
-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.
+if no arguments are specified then the file is interpreted
 
-data types:
-integers and booleans.
+Files:
+Interpret.hs: Handles the interpretation of a program
 
-comments:
-// and /* */ comments are allowed.
+Compile.hs: Compiles the program into a c program
 
+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.
 
+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.
 
 
+semantic rules
+++++++++++++
 
 
+(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]
 
-examples:
+<i := e,c> => c'[i -> v] <= <e,c> => <v,c'>
 
-fib
----
-int n1 = 0;
-int n2 = 1;
-int n = readInt;
+Assign the value v to i in the first scope i is found in.
 
-while(n-- > 0){
-  int temp = n1+n2;
-  n1 = n2;
-  n2 = temp;
-}
-print n2;
+[ENeg]
 
+<e,c> => <-v,c'> <= <e,c> => <v,c'>
 
-tests while, decr and assignment.
 
+[ENot]
 
+<e,c> => <not v,c'> <= <e,c> => <v,c'>
 
-if
---
-if (readBool) {
-  if (readInt < 0)
-    print true;
-  else
-    print false;
-}
+[EVar]
 
+<i,c> => <c(i),c>
 
-tests if and if/else.
+[EInt]
 
+<n,c> => <n,c>
 
+[EBool]
 
-sum
----
-int n;
-int sum = 0;
-while ((n = readInt) != -1) sum = sum + n;
-print sum;
+<b,c> => <b,c>
 
+[EReadI,EReadB]
 
+<c> => <v,c'> <= <IO,c> => <v,c'>
 
+[EPost]
 
-var
----
-int a = 3;
-int b = a - 5;
-int c = a + b*7;
-bool d = a == b;
+<i,c> => <v,c[i->v']> <= c(i) => v, v±1 => v'
 
-tests simple variable operations.
\ No newline at end of file
+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''