Index: src/ControlStruct/Mutate.cc
===================================================================
--- src/ControlStruct/Mutate.cc	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/ControlStruct/Mutate.cc	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -27,16 +27,13 @@
 #include "SynTree/Visitor.h"       // for acceptAll
 
-using namespace std;
+namespace ControlStruct {
+	void fixLabels( std::list< Declaration * > & translationUnit ) {
+		PassVisitor<LabelFixer> lfix;
+		acceptAll( translationUnit, lfix );
+	}
 
-namespace ControlStruct {
-	void mutate( std::list< Declaration * > translationUnit ) {
-		// hoist initialization out of for statements
+	void hoistControlDecls( std::list< Declaration * > & translationUnit ) {
 		PassVisitor<ForExprMutator> formut;
-
-		// normalizes label definitions and generates multi-level exit labels
-		PassVisitor<LabelFixer> lfix;
-
 		mutateAll( translationUnit, formut );
-		acceptAll( translationUnit, lfix );
 	}
 } // namespace CodeGen
Index: src/ControlStruct/Mutate.h
===================================================================
--- src/ControlStruct/Mutate.h	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/ControlStruct/Mutate.h	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// Mutate.h -- 
+// Mutate.h --
 //
 // Author           : Rodolfo G. Esteves
@@ -20,7 +20,11 @@
 class Declaration;
 
+/// Desugars Cforall control structures
 namespace ControlStruct {
-	/// Desugars Cforall control structures
-	void mutate( std::list< Declaration* > translationUnit );
+	/// normalizes label definitions and generates multi-level exit labels
+	void fixLabels( std::list< Declaration * > & translationUnit );
+
+	/// hoist initialization out of for statements
+	void hoistControlDecls( std::list< Declaration * > & translationUnit );
 } // namespace ControlStruct
 
Index: src/Parser/TypedefTable.cc
===================================================================
--- src/Parser/TypedefTable.cc	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/Parser/TypedefTable.cc	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 15:20:13 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue May 22 08:40:01 2018
-// Update Count     : 121
+// Last Modified On : Wed May 30 18:04:38 2018
+// Update Count     : 148
 //
 
@@ -20,7 +20,7 @@
 #if 0
 #include <iostream>
-#define debugPrint( x ) cerr << x
+#define debugPrint( code ) code
 #else
-#define debugPrint( x )
+#define debugPrint( code )
 #endif
 
@@ -29,5 +29,5 @@
 TypedefTable::~TypedefTable() {
 	if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) {
-		// std::cerr << "scope failure " << kindTable.currentScope() << endl;
+		std::cerr << "scope failure " << kindTable.currentScope() << endl;
 	} // if
 } // TypedefTable::~TypedefTable
@@ -54,12 +54,19 @@
 void TypedefTable::makeTypedef( const string & name ) {
 	if ( ! typedefTable.exists( name ) ) {
-		typedefTable.addToEnclosingScope( name, TYPEDEFname );
+		typedefTable.addToEnclosingScope( name, TYPEDEFname /*, "MTD"*/ );
 	} // if
 } // TypedefTable::makeTypedef
 
-void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind ) {
+void TypedefTable::addToScope( const std::string & identifier, int kind /*, const char * locn*/ ) {
+	auto scope = kindTable.currentScope();
+	debugPrint( cerr << "Adding at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl );
+	auto ret = kindTable.insertAt( scope, identifier, kind );
+	if ( ! ret.second ) ret.first->second = kind;		// exists => update
+} // TypedefTable::addToScope
+
+void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind /*, const char * locn*/ ) {
 	assert( kindTable.currentScope() >= 1 );
 	auto scope = kindTable.currentScope() - 1;
-	debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << endl );
+	debugPrint( cerr << "Adding2 at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl );
 	auto ret = kindTable.insertAt( scope, identifier, kind );
 	if ( ! ret.second ) ret.first->second = kind;		// exists => update
@@ -68,22 +75,30 @@
 void TypedefTable::enterScope() {
 	kindTable.beginScope();
-	debugPrint( "Entering scope " << kindTable.currentScope() << endl );
+	debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl );
+	debugPrint( print() );
 } // TypedefTable::enterScope
 
 void TypedefTable::leaveScope() {
-	debugPrint( "Leaving scope " << kindTable.currentScope() << endl );
+	debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl );
+	debugPrint( print() );
 	kindTable.endScope();
 } // TypedefTable::leaveScope
 
-// void TypedefTable::print( void ) const {
-// 	for ( KindTable::const_iterator i = table.begin(); i != table.end(); i++) {
-// 		debugPrint( (*i ).first << ": " );
-// 		list< Entry > declList = (*i).second;
-// 		for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
-// 			debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " );
-// 		}
-// 		debugPrint( endl );
-// 	} // for
-// }
+void TypedefTable::print( void ) const {
+	KindTable::size_type scope = kindTable.currentScope();
+	debugPrint( cerr << "[" << scope << "]" );
+	for ( KindTable::const_iterator i = kindTable.begin(); i != kindTable.end(); i++ ) {
+		while ( i.get_level() != scope ) {
+			--scope;
+			debugPrint( cerr << endl << "[" << scope << "]" );
+		} // while
+		debugPrint( cerr << " " << (*i).first << ":" << (*i).second );
+	} // for
+	while ( scope > 0 ) {
+		--scope;
+		debugPrint( cerr << endl << "[" << scope << "]" );
+	}
+	debugPrint( cerr << endl );
+}
 
 // Local Variables: //
Index: src/Parser/TypedefTable.h
===================================================================
--- src/Parser/TypedefTable.h	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/Parser/TypedefTable.h	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 15:24:36 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue May 22 08:39:29 2018
-// Update Count     : 77
+// Last Modified On : Wed May 30 17:02:49 2018
+// Update Count     : 82
 //
 
@@ -32,8 +32,11 @@
 	void changeKind( const std::string & identifier, int kind );
 	void makeTypedef( const std::string & name );
-	void addToEnclosingScope( const std::string & identifier, int kind );
+	void addToScope( const std::string & identifier, int kind /*, const char **/ );
+	void addToEnclosingScope( const std::string & identifier, int kind /*, const char */ );
 
 	void enterScope();
 	void leaveScope();
+
+	void print( void ) const;
 }; // TypedefTable
 
Index: src/Parser/parser.yy
===================================================================
--- src/Parser/parser.yy	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/Parser/parser.yy	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -10,6 +10,6 @@
 // Created On       : Sat Sep  1 20:22:55 2001
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Mon May 28 17:01:36 2018
-// Update Count     : 3383
+// Last Modified On : Thu May 31 15:11:40 2018
+// Update Count     : 3444
 //
 
@@ -265,5 +265,5 @@
 %type<sn> statement						labeled_statement			compound_statement
 %type<sn> statement_decl				statement_decl_list			statement_list_nodecl
-%type<sn> selection_statement
+%type<sn> selection_statement			if_statement
 %type<sn> switch_clause_list_opt		switch_clause_list
 %type<en> case_value
@@ -332,5 +332,5 @@
 %type<decl> c_declaration static_assert
 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
-%type<decl> KR_declaration_list KR_declaration_list_opt
+%type<decl> KR_parameter_list KR_parameter_list_opt
 
 %type<decl> parameter_declaration parameter_list parameter_type_list_opt
@@ -404,26 +404,30 @@
 //************************* Namespace Management ********************************
 
-// The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
-// "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical.  While it is possible to write a purely
-// context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.
-// Hence, this grammar uses the ANSI style.
-//
-// Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
-// introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types.  This latter
-// type name creates a third class of identifiers that must be distinguished by the scanner.
-//
-// Since the scanner cannot distinguish among the different classes of identifiers without some context information, it
-// accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read.  Semantic
-// actions during the parser update this data structure when the class of identifiers change.
-//
-// Because the Cforall language is block-scoped, an identifier can change its class in a local scope; it must revert to
-// its original class at the end of the block.  Since type names can be local to a particular declaration, each
-// declaration is itself a scope.  This requires distinguishing between type names that are local to the current
-// declaration scope and those that persist past the end of the declaration (i.e., names defined in "typedef" or "otype"
-// declarations).
-//
-// The non-terminals "push" and "pop" denote the opening and closing of scopes.  Every push must have a matching pop,
-// although it is regrettable the matching pairs do not always occur within the same rule.  These non-terminals may
-// appear in more contexts than strictly necessary from a semantic point of view.
+// The C grammar is not context free because it relies on the distinct terminal symbols "identifier" and "TYPEDEFname",
+// which are lexically identical.
+//
+//   typedef int foo; // identifier foo must now be scanned as TYPEDEFname
+//   foo f;           // to allow it to appear in this context
+//
+// While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship
+// between syntactic and semantic constructs.  Cforall compounds this problem by introducing type names local to the
+// scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type
+// generators" -- parameterized types.  This latter type name creates a third class of identifiers, "TYPEGENname", which
+// must be distinguished by the lexical scanner.
+//
+// Since the scanner cannot distinguish among the different classes of identifiers without some context information,
+// there is a type table (typedefTable), which holds type names and identifiers that override type names, for each named
+// scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For
+// each context that introduces a name scope, a new level is created in the type table and that level is popped on
+// exiting the scope.  Since type names can be local to a particular declaration, each declaration is itself a scope.
+// This requires distinguishing between type names that are local to the current declaration scope and those that
+// persist past the end of the declaration (i.e., names defined in "typedef" or "otype" declarations).
+//
+// The non-terminals "push" and "pop" denote the opening and closing of named scopes. Every push has a matching pop in
+// the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push
+// around the list separator.
+//
+//  int f( forall(T) T (*f1) T , forall( S ) S (*f2)( S ) );
+//      push               pop   push                   pop
 
 push:
@@ -854,8 +858,8 @@
 //	| '[' push assignment_expression pop ']'
 //		{ $$ = new ExpressionNode( build_tuple( $3 ) ); }
-	'[' push ',' tuple_expression_list pop ']'
-		{ $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
-	| '[' push assignment_expression ',' tuple_expression_list pop ']'
-		{ $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
+	'[' ',' tuple_expression_list ']'
+		{ $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
+	| '[' push assignment_expression pop ',' tuple_expression_list ']'
+		{ $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
 	;
 
@@ -909,18 +913,15 @@
 	'{' '}'
 		{ $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
-	| '{'
-		// Two scopes are necessary because the block itself has a scope, but every declaration within the block also
-		// requires its own scope.
-	  push push
+	| '{' push
 	  local_label_declaration_opt						// GCC, local labels
 	  statement_decl_list								// C99, intermix declarations and statements
 	  pop '}'
-		{ $$ = new StatementNode( build_compound( $5 ) ); }
+		{ $$ = new StatementNode( build_compound( $4 ) ); }
 	;
 
 statement_decl_list:									// C99
 	statement_decl
-	| statement_decl_list push statement_decl
-		{ if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
+	| statement_decl_list statement_decl
+		{ if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
 	;
 
@@ -940,5 +941,5 @@
 			$$ = new StatementNode( $2 );
 		}
-	| statement pop
+	| statement
 	;
 
@@ -955,12 +956,11 @@
 
 selection_statement:
-	IF '(' push if_control_expression ')' statement		%prec THEN
-		// explicitly deal with the shift/reduce conflict on if/else
-		{ $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
-	| IF '(' push if_control_expression ')' statement ELSE statement
-		{ $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
+			// pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving
+			// the inherent S/R conflict with THEN/ELSE.
+	push if_statement pop
+		{ $$ = $2; }
 	| SWITCH '(' comma_expression ')' case_clause
 		{ $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
-	| SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
+	| SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
 		{
 			StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
@@ -974,5 +974,5 @@
 	| CHOOSE '(' comma_expression ')' case_clause		// CFA
 		{ $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
-	| CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
+	| CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
 		{
 			StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
@@ -981,10 +981,19 @@
 	;
 
+if_statement:
+	IF '(' if_control_expression ')' statement			%prec THEN
+		// explicitly deal with the shift/reduce conflict on if/else
+		{ $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
+	| IF '(' if_control_expression ')' statement ELSE statement
+		{ $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
+	;
+
+
 if_control_expression:
-	comma_expression pop
+	comma_expression
 		{ $$ = new IfCtl( nullptr, $1 ); }
-	| c_declaration pop									// no semi-colon
+	| c_declaration										// no semi-colon
 		{ $$ = new IfCtl( $1, nullptr ); }
-	| cfa_declaration pop								// no semi-colon
+	| cfa_declaration									// no semi-colon
 		{ $$ = new IfCtl( $1, nullptr ); }
 	| declaration comma_expression						// semi-colon separated
@@ -1047,11 +1056,11 @@
 	| DO statement WHILE '(' comma_expression ')' ';'
 		{ $$ = new StatementNode( build_while( $5, $2, true ) ); }
-	| FOR '(' push for_control_expression ')' statement
+	| FOR '(' push for_control_expression ')' statement pop
 		{ $$ = new StatementNode( build_for( $4, $6 ) ); }
 	;
 
 for_control_expression:
-	comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
-		{ $$ = new ForCtl( $1, $4, $6 ); }
+	comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
+		{ $$ = new ForCtl( $1, $3, $5 ); }
 	| declaration comma_expression_opt ';' comma_expression_opt // C99
 		{ $$ = new ForCtl( $1, $2, $4 ); }
@@ -1175,8 +1184,8 @@
 
 handler_clause:
-	handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
-		{ $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
-	| handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
-		{ $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
+	handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
+		{ $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); }
+	| handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
+		{ $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); }
 	;
 
@@ -1282,5 +1291,5 @@
 
 declaration_list_opt:									// used at beginning of switch statement
-	pop	// empty
+	// empty
 		{ $$ = nullptr; }
 	| declaration_list
@@ -1289,18 +1298,18 @@
 declaration_list:
 	declaration
-	| declaration_list push declaration
-		{ $$ = $1->appendList( $3 ); }
-	;
-
-KR_declaration_list_opt:								// used to declare parameter types in K&R style functions
+	| declaration_list declaration
+		{ $$ = $1->appendList( $2 ); }
+	;
+
+KR_parameter_list_opt:								// used to declare parameter types in K&R style functions
 	// empty
 		{ $$ = nullptr; }
-	| KR_declaration_list
-	;
-
-KR_declaration_list:
+	| KR_parameter_list
+	;
+
+KR_parameter_list:
 	push c_declaration pop ';'
 		{ $$ = $2; }
-	| KR_declaration_list push c_declaration pop ';'
+	| KR_parameter_list push c_declaration pop ';'
 		{ $$ = $1->appendList( $3 ); }
 	;
@@ -1322,6 +1331,6 @@
 
 declaration:											// old & new style declarations
-	c_declaration pop ';'
-	| cfa_declaration pop ';'							// CFA
+	c_declaration ';'
+	| cfa_declaration ';'								// CFA
 	| static_assert
 	;
@@ -1431,15 +1440,15 @@
 	TYPEDEF cfa_variable_specifier
 		{
-			typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ );
 			$$ = $2->addTypedef();
 		}
 	| TYPEDEF cfa_function_specifier
 		{
-			typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ );
 			$$ = $2->addTypedef();
 		}
 	| cfa_typedef_declaration pop ',' push no_attr_identifier
 		{
-			typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ );
 			$$ = $1->appendList( $1->cloneType( $5 ) );
 		}
@@ -1452,25 +1461,25 @@
 	TYPEDEF type_specifier declarator
 		{
-			typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ );
 			$$ = $3->addType( $2 )->addTypedef();
 		}
 	| typedef_declaration pop ',' push declarator
 		{
-			typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ );
 			$$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
 		}
 	| type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
 		{
-			typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ );
 			$$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
 		}
 	| type_specifier TYPEDEF declarator
 		{
-			typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ );
 			$$ = $3->addType( $1 )->addTypedef();
 		}
 	| type_specifier TYPEDEF type_qualifier_list declarator
 		{
-			typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ );
 			$$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
 		}
@@ -1599,6 +1608,6 @@
 
 forall:
-	FORALL '(' push type_parameter_list pop ')'					// CFA
-		{ $$ = DeclarationNode::newForall( $4 ); }
+	FORALL '(' type_parameter_list ')'					// CFA
+		{ $$ = DeclarationNode::newForall( $3 ); }
 	;
 
@@ -2192,5 +2201,5 @@
 type_parameter:											// CFA
 	type_class no_attr_identifier_or_type_name
-		{ typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
+		{ typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); }
 	  type_initializer_opt assertion_list_opt
 		{ $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
@@ -2228,6 +2237,6 @@
 	| '|' '{' push trait_declaration_list pop '}'
 		{ $$ = $4; }
-	| '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
-		{ SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
+	// | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
+	// 	{ SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
 	;
 
@@ -2261,19 +2270,19 @@
 	no_attr_identifier_or_type_name
 		{
-			typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
+			typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ );
 			$$ = DeclarationNode::newTypeDecl( $1, 0 );
 		}
-	| no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
-		{
-			typedefTable.addToEnclosingScope( *$1, TYPEGENname );
-			$$ = DeclarationNode::newTypeDecl( $1, $4 );
+	| no_attr_identifier_or_type_name '(' type_parameter_list ')'
+		{
+			typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ );
+			$$ = DeclarationNode::newTypeDecl( $1, $3 );
 		}
 	;
 
 trait_specifier:										// CFA
-	TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
-		{ $$ = DeclarationNode::newTrait( $2, $5, 0 ); }
-	| TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}'
-		{ $$ = DeclarationNode::newTrait( $2, $5, $10 ); }
+	TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
+		{ $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
+	| TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
+		{ $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
 	;
 
@@ -2313,8 +2322,9 @@
 
 external_definition_list:
-	external_definition
+	push external_definition pop
+		{ $$ = $2; }
 	| external_definition_list
 		{ forall = xxx; }
-	  push external_definition
+	  push external_definition pop
 		{ $$ = $1 ? $1->appendList( $4 ) : $4; }
 	;
@@ -2338,9 +2348,13 @@
 			linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
 		}
-	  '{' external_definition_list_opt '}'
+			// SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope.  However,
+			// external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The
+			// correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt.  This
+			// trick works for nested extern "X"s, as each one undoes itself in the nesting.
+	  '{' pop external_definition_list_opt push '}'
 		{
 			linkage = linkageStack.top();
 			linkageStack.pop();
-			$$ = $5;
+			$$ = $6;
 		}
 	| EXTENSION external_definition						// GCC, multiple __extension__ allowed, meaning unknown
@@ -2351,7 +2365,7 @@
 	| type_qualifier_list
 		{ if ( $1->type->forall ) xxx = forall = true; } // remember generic type
-	  push '{' external_definition_list '}'				// CFA, namespace
-		{
-			for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
+	  '{' external_definition_list push '}'			 // CFA, namespace
+		{
+			for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
 				if ( isMangled( iter->linkage ) ) {		// ignore extern "C"
 					iter->addQualifiers( $1->clone() );
@@ -2360,11 +2374,11 @@
  			xxx = false;
 			delete $1;
-			$$ = $5;
+			$$ = $4;
 		}
 	| declaration_qualifier_list
 		{ if ( $1->type->forall ) xxx = forall = true; } // remember generic type
-	  push '{' external_definition_list '}'				// CFA, namespace
-		{
-			for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
+	  '{' external_definition_list '}'					 // CFA, namespace
+		{
+			for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
 				if ( isMangled( iter->linkage ) ) {		// ignore extern "C"
 					iter->addQualifiers( $1->clone() );
@@ -2373,5 +2387,5 @@
  			xxx = false;
 			delete $1;
-			$$ = $5;
+			$$ = $4;
 		}
 	| declaration_qualifier_list type_qualifier_list
@@ -2380,7 +2394,7 @@
 			if ( $2->type->forall ) xxx = forall = true; // remember generic type
 		}
-	  push '{' external_definition_list '}'				// CFA, namespace
-		{
-			for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
+	  '{' external_definition_list '}'					// CFA, namespace
+		{
+			for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
 				if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) {	// ignore extern "C"
 					iter->addQualifiers( $1->clone() );
@@ -2391,5 +2405,5 @@
 			delete $1;
 			delete $2;
-			$$ = $6;
+			$$ = $5;
 		}
 	;
@@ -2404,5 +2418,5 @@
 	| function_declarator compound_statement
 		{ $$ = $1->addFunctionBody( $2 ); }
-	| KR_function_declarator KR_declaration_list_opt compound_statement
+	| KR_function_declarator KR_parameter_list_opt compound_statement
 		{ $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
 	;
@@ -2444,5 +2458,5 @@
 
 		// Old-style K&R function definition, OBSOLESCENT (see 4)
-	| declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
+	| declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
 		{
 			rebindForall( $1, $2 );
@@ -2450,11 +2464,11 @@
 		}
 		// handles default int return type, OBSOLESCENT (see 1)
-	| type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
+	| type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
 		{ $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
 		// handles default int return type, OBSOLESCENT (see 1)
-	| declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
+	| declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
 		{ $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
 		// handles default int return type, OBSOLESCENT (see 1)
-	| declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
+	| declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
 		{ $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
 	;
@@ -2701,5 +2715,5 @@
 	typedef
 		// hide type name in enclosing scope by variable name
-		{ typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
+		{ typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); }
 	| '(' paren_type ')'
 		{ $$ = $2; }
@@ -3191,7 +3205,7 @@
 	'[' push cfa_abstract_parameter_list pop ']'
 		{ $$ = DeclarationNode::newTuple( $3 ); }
-	| '[' push type_specifier_nobody ELLIPSIS ']'
+	| '[' push type_specifier_nobody ELLIPSIS pop ']'
 		{ SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
-	| '[' push type_specifier_nobody ELLIPSIS constant_expression ']'
+	| '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
 		{ SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
 	;
Index: src/ResolvExpr/Alternative.cc
===================================================================
--- src/ResolvExpr/Alternative.cc	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/ResolvExpr/Alternative.cc	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -27,5 +27,5 @@
 
 namespace ResolvExpr {
-	Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0 ) {}
+	Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ) {}
 
 	Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost )
@@ -48,5 +48,5 @@
 	}
 
-	Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env ) {
+	Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( std::move( other.env ) ) {
 		other.expr = nullptr;
 	}
@@ -58,5 +58,5 @@
 		cvtCost = other.cvtCost;
 		expr = other.expr;
-		env = other.env;
+		env = std::move( other.env );
 		other.expr = nullptr;
 		return *this;
Index: src/ResolvExpr/AlternativeFinder.cc
===================================================================
--- src/ResolvExpr/AlternativeFinder.cc	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/ResolvExpr/AlternativeFinder.cc	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -299,6 +299,6 @@
 		// it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value
 		std::unique_ptr<Expression> aggrExpr( alt.expr->clone() );
-		alt.env.apply( aggrExpr->get_result() );
-		Type * aggrType = aggrExpr->get_result();
+		alt.env.apply( aggrExpr->result );
+		Type * aggrType = aggrExpr->result;
 		if ( dynamic_cast< ReferenceType * >( aggrType ) ) {
 			aggrType = aggrType->stripReferences();
@@ -306,8 +306,8 @@
 		}
 
-		if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
+		if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->result ) ) {
 			NameExpr nameExpr( "" );
 			addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr );
-		} else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
+		} else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->result ) ) {
 			NameExpr nameExpr( "" );
 			addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr );
@@ -320,13 +320,16 @@
 		NameExpr * nameExpr = dynamic_cast< NameExpr * >( member );
 		if ( ! nameExpr ) return;
-		const std::string & name = nameExpr->get_name();
+		const std::string & name = nameExpr->name;
 		std::list< Declaration* > members;
 		aggInst->lookup( name, members );
 
-		for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
-			if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) {
-				alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) );
-				renameTypes( alternatives.back().expr );
-				addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression.
+		for ( Declaration * decl : members ) {
+			if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) {
+				// addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so
+				// can't construct in place and use vector::back
+				Alternative newAlt( new MemberExpr( dwt, expr->clone() ), env, newCost );
+				renameTypes( newAlt.expr );
+				addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression.
+				alternatives.push_back( std::move(newAlt) );
 			} else {
 				assert( false );
@@ -1379,5 +1382,8 @@
 			Cost cost = Cost::zero;
 			Expression * newExpr = data.combine( cost );
-			alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) );
+
+			// addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so
+			// can't construct in place and use vector::back
+			Alternative newAlt( newExpr, env, Cost::zero, cost );
 			PRINT(
 				std::cerr << "decl is ";
@@ -1388,6 +1394,7 @@
 				std::cerr << std::endl;
 			)
-			renameTypes( alternatives.back().expr );
-			addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression.
+			renameTypes( newAlt.expr );
+			addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression.
+			alternatives.push_back( std::move(newAlt) );
 		} // for
 	}
Index: src/ResolvExpr/TypeEnvironment.cc
===================================================================
--- src/ResolvExpr/TypeEnvironment.cc	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/ResolvExpr/TypeEnvironment.cc	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -50,5 +50,5 @@
 	}
 
-	EqvClass::EqvClass() : type( 0 ), allowWidening( true ) {
+	EqvClass::EqvClass() : type( nullptr ), allowWidening( true ) {
 	}
 
@@ -159,6 +159,6 @@
 
 	void TypeEnvironment::print( std::ostream &os, Indenter indent ) const {
-		for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i ) {
-			i->print( os, indent );
+		for ( const EqvClass & theClass : env ) {
+			theClass.print( os, indent );
 		} // for
 	}
Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/SymTab/Validate.cc	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -48,4 +48,5 @@
 #include "CodeGen/CodeGenerator.h"     // for genName
 #include "CodeGen/OperatorTable.h"     // for isCtorDtor, isCtorDtorAssign
+#include "ControlStruct/Mutate.h"      // for ForExprMutator
 #include "Common/PassVisitor.h"        // for PassVisitor, WithDeclsToAdd
 #include "Common/ScopedMap.h"          // for ScopedMap
@@ -76,5 +77,4 @@
 class SwitchStmt;
 
-
 #define debugPrint( x ) if ( doDebug ) { std::cout << x; }
 
@@ -275,4 +275,5 @@
 		Concurrency::applyKeywords( translationUnit );
 		acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
+		ControlStruct::hoistControlDecls( translationUnit );  // hoist initialization out of for statements; must happen before autogenerateRoutines
 		autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
 		Concurrency::implementMutexFuncs( translationUnit );
Index: src/SynTree/ReferenceToType.cc
===================================================================
--- src/SynTree/ReferenceToType.cc	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/SynTree/ReferenceToType.cc	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -50,8 +50,8 @@
 
 namespace {
-	void doLookup( const std::list< Declaration* > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {
-		for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
-			if ( (*i)->get_name() == name ) {
-				foundDecls.push_back( *i );
+	void doLookup( const std::list< Declaration * > & members, const std::string & name, std::list< Declaration* > & foundDecls ) {
+		for ( Declaration * decl : members ) {
+			if ( decl->name == name ) {
+				foundDecls.push_back( decl );
 			} // if
 		} // for
@@ -60,5 +60,5 @@
 
 StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) :
-		Parent( tq, baseStruct->get_name(), attributes ), baseStruct( baseStruct ) {}
+		Parent( tq, baseStruct->name, attributes ), baseStruct( baseStruct ) {}
 
 std::string StructInstType::typeString() const { return "struct"; }
@@ -84,5 +84,5 @@
 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
 	assert( baseStruct );
-	doLookup( baseStruct->get_members(), name, foundDecls );
+	doLookup( baseStruct->members, name, foundDecls );
 }
 
@@ -103,5 +103,5 @@
 
 UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) :
-		Parent( tq, baseUnion->get_name(), attributes ), baseUnion( baseUnion ) {}
+		Parent( tq, baseUnion->name, attributes ), baseUnion( baseUnion ) {}
 
 std::string UnionInstType::typeString() const { return "union"; }
@@ -127,5 +127,5 @@
 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
 	assert( baseUnion );
-	doLookup( baseUnion->get_members(), name, foundDecls );
+	doLookup( baseUnion->members, name, foundDecls );
 }
 
Index: src/main.cc
===================================================================
--- src/main.cc	(revision 597c34a361d0410d2480af5d9e812b7978499c8a)
+++ src/main.cc	(revision 41e16b1592d7e5dd5bb62b8283d0d6eef4ccce5a)
@@ -10,6 +10,6 @@
 // Created On       : Fri May 15 23:12:02 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Mon May  7 14:35:57 2018
-// Update Count     : 492
+// Last Modified On : Wed May 30 17:53:14 2018
+// Update Count     : 496
 //
 
@@ -264,5 +264,5 @@
 		} // if
 
-		PASS( "mutate", ControlStruct::mutate( translationUnit ) );
+		PASS( "fixLabels", ControlStruct::fixLabels( translationUnit ) );
 		PASS( "fixNames", CodeGen::fixNames( translationUnit ) );
 		PASS( "genInit", InitTweak::genInit( translationUnit ) );
@@ -573,5 +573,4 @@
 	yyin = input;
 	yylineno = 1;
-	typedefTable.enterScope();
 	int parseStatus = yyparse();
 
