Index: src/examples/Makefile.in
===================================================================
--- src/examples/Makefile.in	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/Makefile.in	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,50 @@
+######################### -*- Mode: Makefile-Gmake -*- ########################
+##
+## Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+##
+## The contents of this file are covered under the licence agreement in the
+## file "LICENCE" distributed with Cforall.
+##
+## Makefile.in -- 
+##
+## Author           : Peter A. Buhr
+## Created On       : Sat May 16 11:34:24 2015
+## Last Modified By : Peter A. Buhr
+## Last Modified On : Sat May 16 11:35:25 2015
+## Update Count     : 2
+###############################################################################
+
+CC := @CFA_BINDIR@/cfa
+CFLAGS = -g -Wall -Wno-unused-function -MMD
+MAKEFILE_NAME = ${firstword ${MAKEFILE_LIST}}	# makefile name
+
+OBJECTS1 = iostream.o fstream.o fstream_test.o
+EXEC1 = fstream_test
+
+OBJECTS2 = vector_int.o fstream.o iostream.o array.o iterator.o vector_test.o
+EXEC2 = vector_test
+
+OBJECTS = ${OBJECTS1} ${OBJECTS2}		# all object files
+DEPENDS = ${OBJECTS:.o=.d}			# substitute ".o" with ".d"
+EXECS = ${EXEC1} ${EXEC2}			# all executables
+
+########## Targets ##########
+
+.PHONY : all clean				# not file names
+
+all : ${EXECS}					# build all executables
+
+${EXEC1} : ${OBJECTS1}				# link step 1st executable
+	${CC} ${CFLAGS} $^ -o $@		# additional object files before $^
+
+${EXEC2} : ${OBJECTS2}				# link step 2nd executable
+	${CC} ${CFLAGS} $^ -o $@		# additional object files before $^
+
+${OBJECTS} : ${MAKEFILE_NAME}			# OPTIONAL : changes to this file => recompile
+
+-include ${DEPENDS}				# include *.d files containing program dependences
+
+clean :						# remove files that can be regenerated
+	rm -f ${DEPENDS} ${OBJECTS} ${EXECS} *.class
+
+distclean : clean
Index: src/examples/abstype.c
===================================================================
--- src/examples/abstype.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/abstype.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,25 @@
+// "cfa-cpp -nx Abstype.c"
+
+type T | { T x( T ); };
+
+T y( T t ) {
+    T t_instance;
+    return x( t );
+}
+
+forall(type T) lvalue T	*?( T* );
+int ?++( int *);
+int ?=?( int*, int );
+forall(dtype DT) DT* ?=?( DT **, DT* );
+
+type U = int*;
+
+U x( U u ) {
+    U u_instance = u;
+    (*u)++;
+    return u;
+}
+
+int *break_abstraction( U u ) {
+    return u;
+}
Index: src/examples/array.c
===================================================================
--- src/examples/array.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/array.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,25 @@
+// "cfa -c -o array.o array.c"
+// "cfa -CFA array.c > array_out.c"
+// "gcc32 array_out.c ../LibCfa/libcfa.a"
+
+#include "array.h"
+
+/// forall( type array_type, elt_type | bounded_array( array_type, elt_type ) )
+/// [ array_iterator begin, array_iterator end ]
+/// get_iterators( array_type array )
+/// {
+///   begin = 0;
+///   end = last( array );
+/// }
+
+// The first element is always at index 0.
+forall( type array_type, type elt_type | bounded_array( array_type, elt_type ) )
+elt_type * begin( array_type array ) {
+    return &array[ 0 ];
+}
+
+// The end iterator should point one past the last element.
+forall( type array_type, type elt_type | bounded_array( array_type, elt_type ) )
+elt_type * end( array_type array ) {
+    return &array[ last( array ) ] + 1;
+}
Index: src/examples/array.h
===================================================================
--- src/examples/array.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/array.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,33 @@
+#ifndef ARRAY_H
+#define ARRAY_H
+
+//#include "iterator.h"
+
+// An array has contiguous elements accessible in any order using integer indicies. The first
+// element has index 0.
+context array( type array_type, type elt_type ) {
+    lvalue elt_type ?[?]( array_type, int );
+};
+
+// A bounded array is an array that carries its maximum index with it.
+context bounded_array( type array_type, type elt_type | array( array_type, elt_type ) ) {
+    int last( array_type );
+};
+
+// implement iterator_for
+
+typedef int array_iterator;
+
+/// forall( type array_type, elt_type | bounded_array( array_type, elt_type ) )
+/// [ array_iterator begin, array_iterator end ] get_iterators( array_type );
+
+
+// A bounded array can be iterated over by using a pointer to the element type. These functions
+// return iterators corresponding to the first element and the one-past-the-end element, STL-style.
+forall( type array_type, type elt_type | bounded_array( array_type, elt_type ) )
+elt_type *begin( array_type );
+
+forall( type array_type, type elt_type | bounded_array( array_type, elt_type ) )
+elt_type *end( array_type );
+
+#endif // ARRAY_H
Index: src/examples/constants.c
===================================================================
--- src/examples/constants.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/constants.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,18 @@
+int foo() {
+    1_234_Ul;
+    -0_177;
+    0x_ff_FF_ff_FF;
+    +9_223_372_036_854_775_807;
+    12.123_333_E_27;
+    0X_1.ff_ff_ff_ff_ff_fff_P_1023;
+    '\0';
+    '\1_2_3';
+    L_'\x_ff_ee';
+    L"a_bc\u_00_40xyz\xff_AA";
+    "a_bc\\
+  u_00_40xyz";
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa -std=c99 constants.c" //
+// End: //
Index: src/examples/control_structures.c
===================================================================
--- src/examples/control_structures.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/control_structures.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,49 @@
+int main() {
+  L1: {
+      L2: switch ( 3_333_333 ) {	// underscores in constant
+	  case 1,2,3:			// 4~8, 4...8 not working
+	  L3: for ( ;; ) {
+	      L4: for ( ;; ) {
+		    break L1;		// labelled break
+		    break L2;
+		    break L3;
+		    break L4;
+#if 0
+		    continue L1;	// labelled continue
+		    continue L2;
+		    continue L3;
+		    continue L4;
+#endif
+		} // for
+	    } // for
+	    break;
+	  default:
+	    break L1;
+	} // switch
+	3;
+	int i, j;
+	choose ( 7 ) {
+	  case 1,2,3:
+	    i = 3;
+	    fallthru;
+	  case 4,5,6:
+	    j = 3;
+	  default: ;
+	} // choose
+    } // block
+
+#if 0
+    try {
+	int i = 3;
+    } catch( int ) {
+    } catch( double ) {
+    } catch( ... ) {
+    } finally {
+    } // try
+#endif
+
+} // main
+
+// Local Variables: //
+// compile-command: "../../bin/cfa control_structures.c" //
+// End: //
Index: src/examples/ctxts.c
===================================================================
--- src/examples/ctxts.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/ctxts.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,9 @@
+context has_f( type T ) {
+    T f( T );
+};
+
+context has_g( type U | has_f( U ) ) {
+    U g( U );
+};
+
+forall( type V | has_g( V ) ) void h( V );
Index: src/examples/esskaykay.c
===================================================================
--- src/examples/esskaykay.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/esskaykay.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,11 @@
+// "./cfa-cpp -cn esskaykay.c"
+
+// forall (type A, type B, type C) C ess (C (*f) (A,B), B (*g) (A), A x) { return f(x,g(x)); }
+forall (type A, type B, type C) C ess (C (*(*f)(A))(B), B (*g)(A), A x) { return f(x)(g(x)); }
+
+// forall (type A, type B) A kay (A a, B b) { return a; }
+forall (type A, type B) A (*kay(A a))(B b);
+
+// Now is the following function well-typed, or not?
+
+forall (type A) A esskaykay (A x) { ess (kay, kay, x); }
Index: src/examples/forward.c
===================================================================
--- src/examples/forward.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/forward.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,13 @@
+forall(type T) lvalue T *?( T* );
+int ?=?( int*, int );
+
+struct q { int y; };
+struct q *x;
+
+void f() {
+    *x;
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa forward.c" //
+// End: //
Index: src/examples/fstream.c
===================================================================
--- src/examples/fstream.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/fstream.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,107 @@
+#include "fstream.h"
+
+extern "C" {
+#include <stdio.h>
+#include <stdlib.h>
+}
+
+struct ofstream {
+    FILE *file;
+    int fail;
+};
+
+ofstream *write( ofstream *os, const char *data, streamsize_type size ) {
+    if ( ! os->fail ) {
+	fwrite( data, size, 1, os->file );
+	os->fail = ferror( os->file );
+    }
+    return os;
+}
+
+int fail( ofstream *os ) {
+    return os->fail;
+}
+
+static ofstream *make_ofstream() {
+    ofstream *new_stream = malloc( sizeof( ofstream ) );
+    new_stream->fail = 0;
+    return new_stream;
+}
+
+ofstream *ofstream_stdout() {
+    ofstream *stdout_stream = make_ofstream();
+    stdout_stream->file = stdout;
+    return stdout_stream;
+}
+
+ofstream *ofstream_stderr() {
+    ofstream *stderr_stream = make_ofstream();
+    stderr_stream->file = stderr;
+    return stderr_stream;
+}
+
+ofstream *ofstream_fromfile( const char *name ) {
+    ofstream *file_stream = make_ofstream();
+    file_stream->file = fopen( name, "w" );
+    file_stream->fail = file_stream->file == 0;
+    return file_stream;
+}
+
+void ofstream_close( ofstream *os ) {
+    if ( os->file != stdout && os->file != stderr ) {
+	os->fail = fclose( os->file );
+    }
+    free( os );
+}
+
+struct ifstream {
+    FILE *file;
+    int fail;
+    int eof;
+};
+
+ifstream *read( ifstream *is, char *data, streamsize_type size ) {
+    if ( ! is->fail && ! is->eof ) {
+	fread( data, size, 1, is->file );
+	is->fail = ferror( is->file );
+	is->eof = feof( is->file );
+    }
+    return is;
+}
+  
+ifstream *unread( ifstream *is, char c ) {
+    if ( ! is->fail ) {
+	if ( ! EOF == ungetc( c, is->file ) ) {
+	    is->fail = 1;
+	}
+    }
+    return is;
+}
+
+int fail( ifstream *is ) {
+    return is->fail;
+}
+
+int eof( ifstream *is ) {
+    return is->eof;
+}
+
+static ifstream *make_ifstream() {
+    ifstream *new_stream = malloc( sizeof( ifstream ) );
+    new_stream->fail = 0;
+    new_stream->eof = 0;
+    return new_stream;
+}
+
+ifstream *ifstream_stdin() {
+    ifstream *stdin_stream = make_ifstream();
+    stdin_stream->file = stdin;
+    return stdin_stream;
+}
+
+ifstream *ifstream_fromfile( const char *name ) {
+    ifstream *file_stream = make_ifstream();
+    file_stream->file = fopen( name, "r" );
+    file_stream->fail = file_stream->file == 0;
+    return file_stream;
+}
Index: src/examples/fstream.h
===================================================================
--- src/examples/fstream.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/fstream.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,28 @@
+#ifndef __FSTREAM_H__
+#define __FSTREAM_H__
+
+#include "iostream.h"
+
+typedef struct ofstream ofstream;
+
+// implement context ostream
+ofstream *write( ofstream *, const char *, streamsize_type );
+int fail( ofstream * );
+
+ofstream *ofstream_stdout();
+ofstream *ofstream_stderr();
+ofstream *ofstream_fromfile( const char *name );
+void ofstream_close( ofstream *os );
+
+typedef struct ifstream ifstream;
+
+// implement context istream
+ifstream *read( ifstream *, char *, streamsize_type );
+ifstream *unread( ifstream *, char );
+int fail( ifstream * );
+int eof( ifstream * );
+
+ifstream *ifstream_stdin();
+ifstream *ifstream_fromfile( const char *name );
+
+#endif // __FSTREAM_H__
Index: src/examples/fstream_test.c
===================================================================
--- src/examples/fstream_test.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/fstream_test.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,10 @@
+#include "fstream.h"
+
+int main() {
+    ofstream *sout = ofstream_stdout();
+    ifstream *sin = ifstream_stdin();
+    int nombre;
+    sout << "Appuyez un nombre, s'il vous plâit:\n";
+    sin >> &nombre;
+    sout << "Vous avez appuyé: " << nombre << "\n";
+}
Index: src/examples/fwrite.c
===================================================================
--- src/examples/fwrite.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/fwrite.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,7 @@
+extern "C" {
+    #include <stdio.h>
+}
+
+int main() {
+    fwrite( "test\n", 5, 1, stdout );
+}
Index: src/examples/hello.c
===================================================================
--- src/examples/hello.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/hello.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,15 @@
+#include "fstream.h"
+
+int main() {
+    ofstream *sout = ofstream_stdout();
+    ifstream *sin = ifstream_stdin();
+    sout << "Bonjour au monde!\n";
+    sout << 3 << " " << 3.5 << " " << 'a' << " " << "abc" << "\n";
+    int i, j, k;
+    sin >> &i >> &j >> &k;
+    sout << "i:" << i << " j:" << j << " k:" << k << "\n";
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa hello.c fstream.o iostream.o" //
+// End: //
Index: src/examples/huge.c
===================================================================
--- src/examples/huge.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/huge.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,6 @@
+int huge( int n, forall( type T ) T (*f)( T ) ) {
+    if ( n <= 0 )
+	return f( 0 );
+    else
+	return huge( n - 1, f( f ) );
+}
Index: src/examples/identity.c
===================================================================
--- src/examples/identity.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/identity.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,23 @@
+#include "fstream.h"
+
+forall( type T )
+T identity( T t ) {
+    return t;
+}
+
+int main() {
+    ofstream *sout = ofstream_stdout();
+    char c = 'a';
+    c = identity( c );
+    sout << c << ' ' << identity( c ) << '\n';
+    int i = 5;
+    i = identity( i );
+    sout << i << ' ' << identity( i ) << '\n';
+    double d = 3.2;
+    d = identity( d );
+    sout << d << ' ' << identity( d ) << '\n';
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa identity.c fstream.o iostream.o" //
+// End: //
Index: src/examples/includes.c
===================================================================
--- src/examples/includes.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/includes.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,41 @@
+#if 1
+//#include <aio.h>		// FAILS -- includes locale.h
+#include <aliases.h>
+#include <alloca.h>
+#include <ansidecl.h>
+#include <ar.h>
+//#include <argp.h>		// FAILS -- includes locale.h
+//#include <argz.h>		// FAILS -- includes locale.h
+#include <assert.h>
+#include <bfd.h>		// contains structure field "type"
+#include <complex.h>
+//#include <ctype.h>		// FAILS -- includes locale.h
+#include <errno.h>
+#include <fenv.h>
+#include <float.h>
+#include <inttypes.h>
+#include <iso646.h>
+#include <limits.h>
+//#include <locale.h>		// FAILS -- "no reasonable alternatives for applying ... Name: ?+? ..."
+#include <math.h>		// contains structure field "type"
+#include <setjmp.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdio.h>
+//#include <string.h>		// FAILS -- includes locale.h
+#include <tgmath.h>
+//#include <time.h>		// FAILS -- includes locale.h
+#include <unistd.h>
+//#include <wchar.h>		// FAILS -- includes locale.h
+//#include <wctype.h>		// FAILS -- includes locale.h
+#include <curses.h>
+#else
+#include <time.h>		// FAILS -- includes locale.h
+#endif // 0
+
+// Local Variables: //
+// compile-command: "../../bin/cfa includes.c" //
+// End: //
Index: src/examples/index.h
===================================================================
--- src/examples/index.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/index.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,5 @@
+context index( type T ) {
+    T ?+?( T, T );
+    T ?-?( T, T );
+    const T 0, 1;
+};
Index: src/examples/iostream.c
===================================================================
--- src/examples/iostream.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/iostream.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,65 @@
+// "cfa -c -o iostream.o iostream.c"
+// "cfa -v -E iostream.c > iostream_out.c"
+// "cfa -CFA iostream.c > iostream_out.c"
+// "cfa iostream_out.c"
+// "gcc32 iostream_out.c LibCfa/libcfa.a"
+
+#include "iostream.h"
+extern "C" {
+#include <stdio.h>
+//#include <string.h>
+//#include <ctype.h>
+typedef long unsigned int size_t;
+size_t strlen(const char *s);
+}
+
+forall( dtype ostype | ostream( ostype ) )
+ostype * ?<<?( ostype *os, char c ) {
+    return write( os, &c, 1 );
+}
+
+forall( dtype ostype | ostream( ostype ) )
+ostype * ?<<?( ostype *os, int i ) {
+    char buffer[20];      // larger than the largest integer
+    sprintf( buffer, "%d", i );
+    return write( os, buffer, strlen( buffer ) );
+}
+
+forall( dtype ostype | ostream( ostype ) )
+ostype * ?<<?( ostype *os, double d ) {
+    char buffer[32];      // larger than the largest double
+    sprintf( buffer, "%g", d );
+    return write( os, buffer, strlen( buffer ) );
+}
+
+forall( dtype ostype | ostream( ostype ) )
+ostype * ?<<?( ostype *os, const char *cp ) {
+    return write( os, cp, strlen( cp ) );
+}
+
+forall( dtype istype | istream( istype ) )
+istype * ?>>?( istype *is, char *cp ) {
+    return read( is, cp, 1 );
+}
+
+forall( dtype istype | istream( istype ) )
+istype * ?>>?( istype *is, int *ip ) {
+    char cur;
+  
+    // skip some whitespace
+    do {
+	is >> &cur;
+	if ( fail( is ) || eof( is ) ) return is;
+    } while ( !( cur >= '0' && cur <= '9' ) );
+  
+    // accumulate digits
+    *ip = 0;
+    while ( cur >= '0' && cur <= '9' ) {
+	*ip = *ip * 10 + ( cur - '0' );
+	is >> &cur;
+	if ( fail( is ) || eof( is ) ) return is;
+    }
+  
+    unread( is, cur );
+    return is;
+}
Index: src/examples/iostream.h
===================================================================
--- src/examples/iostream.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/iostream.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,40 @@
+#ifndef IOSTREAM_H
+#define IOSTREAM_H
+
+typedef unsigned long streamsize_type;
+
+context ostream( dtype ostype ) {
+    ostype *write( ostype *, const char *, streamsize_type );
+    int fail( ostype * );
+};
+
+context writeable( type T ) {
+    forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, T );
+};
+
+// implement writable for some intrinsic types
+
+forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, char );
+forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, int );
+forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double );
+forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * );
+
+
+context istream( dtype istype ) {
+    istype *read( istype *, char *, streamsize_type );
+    istype *unread( istype *, char );
+    int fail( istype * );
+    int eof( istype * );
+};
+
+context readable( type T ) {
+    forall( dtype istype | istream( istype ) ) istype * ?<<?( istype *, T );
+};
+
+forall( dtype istype | istream( istype ) )
+istype * ?>>?( istype *, char * );
+
+forall( dtype istype | istream( istype ) )
+istype * ?>>?( istype *, int * );
+
+#endif // IOSTREAM_H
Index: src/examples/it_out.c
===================================================================
--- src/examples/it_out.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/it_out.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,102 @@
+# 1 "iterator.c"
+# 1 "<built-in>"
+# 1 "<command line>"
+# 1 "iterator.c"
+# 1 "iterator.h" 1
+
+
+
+# 1 "iostream.h" 1
+
+
+
+typedef unsigned long streamsize_type;
+
+
+
+context ostream( dtype os_type )
+{
+
+    os_type *write( os_type *, const char *, streamsize_type );
+
+
+    int fail( os_type * );
+};
+
+
+
+
+context writeable( type T )
+{
+    forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, T );
+};
+
+
+
+forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, char );
+forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, int );
+forall( dtype os_type | ostream( os_type ) ) os_type * ?<<?( os_type *, const char * );
+
+
+
+
+context istream( dtype is_type )
+{
+
+    is_type *read( is_type *, char *, streamsize_type );
+
+
+    is_type *unread( is_type *, char );
+
+
+    int fail( is_type * );
+
+
+    int eof( is_type * );
+};
+
+
+
+
+context readable( type T )
+{
+    forall( dtype is_type | istream( is_type ) ) is_type * ?<<?( is_type *, T );
+};
+
+
+
+forall( dtype is_type | istream( is_type ) ) is_type * ?>>?( is_type *, char* );
+forall( dtype is_type | istream( is_type ) ) is_type * ?>>?( is_type *, int* );
+# 5 "iterator.h" 2
+
+
+context iterator( type iterator_type, type elt_type )
+{
+
+    iterator_type ?++( iterator_type* );
+    iterator_type ++?( iterator_type* );
+
+
+    int ?==?( iterator_type, iterator_type );
+    int ?!=?( iterator_type, iterator_type );
+
+
+    lvalue elt_type *?( iterator_type );
+};
+
+
+
+forall( type elt_type | writeable( elt_type ),
+        type iterator_type | iterator( iterator_type, elt_type ),
+        dtype os_type | ostream( os_type ) )
+void write_all( iterator_type begin, iterator_type end, os_type *os );
+# 2 "iterator.c" 2
+
+forall( type elt_type | writeable( elt_type ),
+        type iterator_type | iterator( iterator_type, elt_type ),
+        dtype os_type | ostream( os_type ) )
+void
+write_all( elt_type begin, iterator_type end, os_type *os )
+{
+    os << begin;
+}
Index: src/examples/iterator.c
===================================================================
--- src/examples/iterator.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/iterator.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,37 @@
+// "cfa iterator.c"
+// "cfa -CFA iterator.c > iterator_out.c"
+// "gcc31 iterator_out.c ../LibCfa/libcfa.a"
+
+#include "iterator.h"
+
+/// forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
+/// void
+/// for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) )
+/// {
+///   iterator_type i;
+///   for ( i = begin; i != end; ++i ) {
+///     func( *i );
+///   }
+/// }
+
+forall( type elt_type | writeable( elt_type ),
+        type iterator_type | iterator( iterator_type, elt_type ),
+        dtype os_type | ostream( os_type ) )
+void write_all( iterator_type begin, iterator_type end, os_type *os ) {
+    iterator_type i;
+    for ( i = begin; i != end; ++i ) {
+	os << *i << ' ';
+    }
+}
+
+forall( type elt_type | writeable( elt_type ),
+	type iterator_type | iterator( iterator_type, elt_type ),
+	dtype os_type | ostream( os_type ) )
+void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
+    iterator_type i; // "= end;" does not work
+    i = end;
+    do {
+	--i;
+	os << *i << ' ';
+    } while ( i != begin );
+}
Index: src/examples/iterator.h
===================================================================
--- src/examples/iterator.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/iterator.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,41 @@
+#ifndef ITERATOR_H
+#define ITERATOR_H
+
+#include "iostream.h"
+
+// An iterator can be used to traverse a data structure.
+context iterator( type iterator_type, type elt_type ) {
+    // point to the next element
+//    iterator_type ?++( iterator_type * );
+    iterator_type ++?( iterator_type * );
+    iterator_type --?( iterator_type * );
+
+    // can be tested for equality with other iterators
+    int ?==?( iterator_type, iterator_type );
+    int ?!=?( iterator_type, iterator_type );
+
+    // dereference to get the pointed-at element
+    lvalue elt_type *?( iterator_type );
+};
+
+context iterator_for ( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {
+//    [ iterator_type begin, iterator_type end ] get_iterators( collection_type );
+    iterator_type begin( collection_type );
+    iterator_type end( collection_type );
+};
+
+forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
+void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
+
+// writes the range [begin, end) to the given stream
+forall( type elt_type | writeable( elt_type ),
+        type iterator_type | iterator( iterator_type, elt_type ),
+        dtype os_type | ostream( os_type ) )
+void write_all( iterator_type begin, iterator_type end, os_type *os );
+
+forall( type elt_type | writeable( elt_type ),
+	type iterator_type | iterator( iterator_type, elt_type ),
+	dtype os_type | ostream( os_type ) )
+void write_reverse( iterator_type begin, iterator_type end, os_type *os );
+
+#endif // ITERATOR_H
Index: src/examples/min.c
===================================================================
--- src/examples/min.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/min.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,28 @@
+extern "C" {
+    int printf( const char *, ... );
+//#include <stdio.h>
+}
+
+forall( type T | { int ?<?( T, T ); } )
+T min( const T t1, const T t2 ) {
+    return t1 < t2 ? t1 : t2;
+}
+
+int main() {
+    char c;
+//    c = min( 'z', 'a' );
+//    printf( "minimum %d\n", c );
+    int i;
+    i = min( 4, 3 );
+    printf( "minimum %d\n", min( 4, 3 ) );
+    float f;
+    f = min( 4.0, 3.1 );
+    printf( "minimum %g\n", f );
+    double d;
+    d = min( 4.0, 3.2 );
+    printf( "minimum %g\n", d );
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa min.c" //
+// End: //
Index: src/examples/new.c
===================================================================
--- src/examples/new.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/new.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,13 @@
+forall( type T )
+void f( T *t ) {
+    t--;
+    *t;
+    ++t;
+    t += 2;
+    t + 2;
+    --t;
+    t -= 2;
+    t - 4;
+    t[7];
+    7[t];
+}
Index: src/examples/prolog.c
===================================================================
--- src/examples/prolog.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/prolog.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,32 @@
+// "./cfa prolog.c"
+
+extern "C" { extern int printf( const char *fmt, ... ); }
+
+void printResult( int x ) { printf( "int\n" ); }
+void printResult( double x ) { printf( "double\n" ); }
+void printResult( char * x ) { printf( "char*\n" ); }
+
+void is_arithmetic( int x ) {}
+void is_arithmetic( double x ) {}
+
+void is_integer( int x ) {}
+
+context ArithmeticType( type T ) {
+    void is_arithmetic( T );
+};
+
+context IntegralType( type T | ArithmeticType( T ) ) {
+    void is_integer( T );
+};
+
+forall( type T | IntegralType( T ) | { void printResult( T ); } )
+void hornclause( T param ) {
+    printResult( param );
+}
+
+int main() {
+    int x;
+    double x;
+    char * x;
+    hornclause( x );
+}
Index: src/examples/quad.c
===================================================================
--- src/examples/quad.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/quad.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,22 @@
+extern "C" {
+    #include <stdio.h>
+}
+
+forall( type T | { T ?*?( T, T ); } )
+T square( T t ) {
+    return t * t;
+}
+
+forall( type U | { U square( U ); } )
+U quad( U u ) {
+    return square( square( u ) );
+}
+
+int main() {
+    int N = 2;
+    printf( "result of quad of %d is %d\n", N, quad( N ) );
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa quad.c" //
+// End: //
Index: src/examples/quoted_keyword.c
===================================================================
--- src/examples/quoted_keyword.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/quoted_keyword.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,20 @@
+// test quoted keyword usage
+int `catch`;
+
+struct {
+    int `type`;
+    int `struct`;
+} st;
+
+typedef int `forall`;
+`forall` `throw`;
+
+int foo() {
+    int w = `catch` + st.`type` + st.`struct` + `throw`;
+}
+
+#include <math.h>	// has field name "type"
+
+// Local Variables: //
+// compile-command: "../../bin/cfa quoted_keyword.c" //
+// End: //
Index: src/examples/rodolfo1.c
===================================================================
--- src/examples/rodolfo1.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/rodolfo1.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,7 @@
+// "./cfa-cpp -c rodolfo1.c"
+
+void f() {
+	int a, b = 4, c = 5;
+	a = b + c;
+	int d = a + 7;
+}
Index: src/examples/rodolfo2.c
===================================================================
--- src/examples/rodolfo2.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/rodolfo2.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,14 @@
+// "./cfa-cpp -c rodolfo2.c"
+
+extern "C" {
+    #include <assert.h>
+}
+
+int a = 7;
+
+void f() {
+    int b;
+    b = a;
+    int a = 8;
+    assert( b == 7 );
+}
Index: src/examples/s.c
===================================================================
--- src/examples/s.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/s.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,8 @@
+//int ?!=?( int, int );
+
+void f() {
+//    int a;
+//    a ? 4 : 5;
+    1 ? 4 : 5;
+    0 ? 4 : 5;
+}
Index: src/examples/simple.c
===================================================================
--- src/examples/simple.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/simple.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,21 @@
+// './cfa square.c'
+
+extern "C" {
+    int printf( const char *fmt, ... );
+}
+
+context has_star( type T ) {
+    T ?*?( T, T );
+};
+
+int ?*?( int, int );
+int ?=?( int*, int );
+
+forall( type T | has_star( T ) )
+T square( T t ) {
+    return t * t;
+}
+
+int main() {
+    printf( "result of square of 5 is %d\n", square( 5 ) );
+}
Index: src/examples/simplePoly.c
===================================================================
--- src/examples/simplePoly.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/simplePoly.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,17 @@
+// './cfa-cpp -nc < simplePoly.c'
+
+forall( type T, type U | { T f( T, U ); } )
+T q( T t, U u )
+{
+    return f( t, u );
+//  return t;
+}
+
+int f( int, double* );
+
+void g( void ) {
+    int y;
+    double x;
+//  if ( y )
+    q( 3, &x );
+}
Index: src/examples/simpler.c
===================================================================
--- src/examples/simpler.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/simpler.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,7 @@
+// "./cfa-cpp -c simpler.c"
+
+forall( type T ) T id( T, T );
+
+int main() {
+    id( 0, 7 );
+}
Index: src/examples/specialize.c
===================================================================
--- src/examples/specialize.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/specialize.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,43 @@
+// "./cfa specialize.c"
+// "./cfa -g simple.c"
+// "./cfa -CFA simple.c > simple_out.c"
+
+/// void f( const int * );
+/// 
+/// void m()
+/// {
+///   f( 0 );
+/// }
+
+/// forall( dtype T ) T* f( T* );
+/// void g( int* (*)(int*) );
+/// 
+/// int m() {
+///   g( f );
+/// }
+
+/// void f1( void (*q)( forall( dtype U ) U* (*p)( U* ) ) );
+/// void g1( int* (*)(int*) );
+/// 
+/// int m1() {
+///   f1( g1 );
+/// }
+
+extern "C" {
+  int printf( const char*, ... );
+}
+
+forall( type T ) T f( T t )
+{
+  printf( "in f; sizeof T is %d\n", sizeof( T ) );
+  return t;
+}
+
+void g( int (*p)(int) )
+{
+  printf( "g: f(7) returned %d\n", f(7) );
+}
+
+int main() {
+  g( f );
+}
Index: src/examples/square.c
===================================================================
--- src/examples/square.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/square.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,13 @@
+extern "C" {
+#include <stdio.h>
+}
+
+forall( type T | { T ?*?( T, T ); })
+T square( T t ) {
+    return t * t;
+}
+
+int main() {
+    printf( "result of square of 5 is %d\n", square( 5 ) );
+    printf( "result of square of 5 is %f\n", square( 5.0 ) );
+}
Index: src/examples/square.cf
===================================================================
--- src/examples/square.cf	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/square.cf	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,20 @@
+// './cfa square.c'
+
+#undef __cplusplus
+extern "C" {
+#include <stdio.h>
+}
+
+forall( type T | { T ?*?( T, T ); })
+T
+square( T t )
+{
+  return t * t;
+}
+
+int
+main()
+{
+  printf( "result of square of 5 is %d\n", square( 5 ) );
+  return 0;
+}
Index: src/examples/sum.c
===================================================================
--- src/examples/sum.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/sum.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,56 @@
+extern "C" {
+    int printf( const char *, ... );
+}
+
+context sumable( type T ) {
+    const T 0;
+    T ?+?( T, T );
+    T ?++( T * );
+    T ?+=?( T *, T );
+};
+
+forall( type T | sumable( T ) )
+T sum( int n, T a[] ) {
+    T total;				// instantiate T, select 0
+    total = 0;
+    for ( int i = 0; i < n; i += 1 )
+	total = total + a[i];		// select +
+    return total;
+}
+
+// Required to satisfy sumable as char does not have addition.
+const char 0;
+char ?+?( char op1, char op2 ) { return op1 + op2; }
+char ?++( char *op ) { return *op + 1; }
+
+const double 0; // TEMPORARY, incorrect use of int 0
+
+int main() {
+    const int size = 10, low = 0, High = 10;
+    int si = 0, ai[10]; // size
+    int i;
+    for ( i = low; i < High; i += 1 ) {
+	si += i;
+	ai[i] = i;
+    }
+    printf( "sum from %d to %d is %d, check %d\n",
+	    low, High, sum( size, ai ), si );
+
+//    char ci[10];
+//    char c = sum( size, ci );
+//    float fi[10];
+//    float f = sum( size, fi );
+
+    double sd = 0.0, ad[10]; // size
+    for ( i = low; i < High; i += 1 ) {
+	double d = i / (double)size;
+	sd += d;
+	ad[i] = d;
+    }
+    printf( "sum from %g to %g is %g, check %g\n",
+	    low / (double)size, High / (double)size, sum( size, ad ), sd );
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa sum.c" //
+// End: //
Index: src/examples/swap.c
===================================================================
--- src/examples/swap.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/swap.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,21 @@
+extern "C" {
+    int printf( const char *, ... );
+}
+
+forall( type T )
+void swap( T *left, T *right ) {
+    T temp = *left;
+    *left = *right;
+    *right = temp;
+}
+
+int main() {
+    int x = 1, y = 2;
+    printf( "%d %d\n", x, y );
+    swap( &x, &y );
+    printf( "%d %d\n", x, y );
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa swap.c" //
+// End: //
Index: src/examples/twice.c
===================================================================
--- src/examples/twice.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/twice.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,15 @@
+#include "fstream.h"
+
+forall( type T | { T ?+?( T, T ); T ?++( T * ); [T] ?+=?( T *, T ); } )
+T twice( const T t ) {
+    return t + t;
+}
+
+int main() {
+    ofstream *sout = ofstream_stdout();
+    sout << twice( 1 ) << ' ' << twice( 3.2 ) << '\n';
+}
+
+// Local Variables: //
+// compile-command: "../../bin/cfa twice.c fstream.o iostream.o" //
+// End: //
Index: src/examples/vector_int.c
===================================================================
--- src/examples/vector_int.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/vector_int.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,52 @@
+// "cfa vector_int.c"
+
+#include "vector_int.h"
+extern "C" {
+#include <stdlib.h>
+#include <assert.h>
+}
+
+#define DEFAULT_CAPACITY 20
+
+vector_int vector_int_allocate() {
+    return vector_int_allocate( DEFAULT_CAPACITY );
+}
+
+vector_int vector_int_allocate( int reserve ) {
+    vector_int new_vector;
+    new_vector.last = -1;
+    new_vector.capacity = reserve;
+    new_vector.data = malloc( sizeof( int ) * reserve );
+    return new_vector;
+}
+
+void vector_int_deallocate( vector_int vec ) {
+    free( vec.data );
+}
+
+void reserve( vector_int *vec, int reserve ) {
+    if ( reserve > vec->capacity ) {
+	vec->data = realloc( vec->data, sizeof( int ) * reserve );
+	vec->capacity = reserve;
+    }
+}
+
+void append( vector_int *vec, int element ) {
+    vec->last++;
+    if ( vec->last == vec->capacity ) {
+	vec->capacity *= 2;
+	vec->data = realloc( vec->data, sizeof( int ) * vec->capacity );
+    }
+    vec->data[ vec->last ] = element;
+}
+
+// implement bounded_array
+
+lvalue int ?[?]( vector_int vec, int index ) {
+    return vec.data[ index ];
+}
+
+int last( vector_int vec ) {
+    return vec.last;
+}
+
Index: src/examples/vector_int.h
===================================================================
--- src/examples/vector_int.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/vector_int.h	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,24 @@
+#ifndef VECTOR_INT_H
+#define VECTOR_INT_H
+
+// A flexible array, similar to a C++ vector, that holds integers and can be resized dynamically
+
+typedef struct vector_int {
+    int last;						// last used index
+    int capacity;					// last possible index before reallocation
+    int *data;						// array
+} vector_int;
+
+vector_int vector_int_allocate();			// allocate vector with default capacity
+vector_int vector_int_allocate( int reserve );		// allocate vector with specified capacity
+void vector_int_deallocate( vector_int );		// deallocate vector's storage
+
+void reserve( vector_int *vec, int reserve );		// reserve more capacity
+void append( vector_int *vec, int element );		// add element to end of vector, resizing as necessary
+
+// implement bounded_array
+
+lvalue int ?[?]( vector_int vec, int index );		// access to arbitrary element (does not resize)
+int last( vector_int vec );				// return last element
+
+#endif // VECTOR_INT_H
Index: src/examples/vector_test.c
===================================================================
--- src/examples/vector_test.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
+++ src/examples/vector_test.c	(revision 843054c23fcb725d2486e5e42e91b3741bc523b8)
@@ -0,0 +1,36 @@
+#include "fstream.h"
+#include "vector_int.h"
+#include "array.h"
+#include "iterator.h"
+
+int main() {
+    ofstream *sout = ofstream_stdout();
+    ifstream *sin = ifstream_stdin();
+    vector_int vec = vector_int_allocate();
+
+    // read in numbers until EOF or error
+    int num;
+
+    sout << "enter N elements and C-d on a separate line:\n";
+    for ( ;; ) {
+	sin >> &num;
+      if ( fail( sin ) || eof( sin ) ) break;
+	append( &vec, num );
+    }
+    // write out the numbers
+
+    sout << "Array elements:\n";
+//    write_all( begin( vec ), end( vec ), sout );
+//    sout << "\n";
+    for ( int index = 0; index <= last( vec ); index += 1 ) {
+	sout << vec[ index ] << " ";
+    }
+    sout << "\n";
+#if 1
+    sout << "Array elements reversed:\n";
+    write_reverse( begin( vec ), end( vec ), sout );
+    sout << "\n";
+#endif
+}
+
+// ../bin/cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o
