Index: src/Parser/parser.yy
===================================================================
--- src/Parser/parser.yy	(revision cb4bbb6de3060dfc3c911c1f4a0f4e1e4f3aff30)
+++ src/Parser/parser.yy	(revision 35718a956595deb97b970ddc59681cb3586e8fcc)
@@ -10,6 +10,6 @@
 // Created On       : Sat Sep  1 20:22:55 2001
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue May 29 07:24:32 2018
-// Update Count     : 3387
+// Last Modified On : Wed May 30 20:29:03 2018
+// Update Count     : 3432
 //
 
@@ -330,5 +330,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
@@ -892,18 +892,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; } }
 	;
 
@@ -923,5 +920,5 @@
 			$$ = new StatementNode( $2 );
 		}
-	| statement pop
+	| statement
 	;
 
@@ -938,12 +935,12 @@
 
 selection_statement:
-	IF '(' push if_control_expression ')' statement		%prec THEN
+	IF '(' push if_control_expression ')' statement pop		%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
+	| IF '(' push if_control_expression ')' statement ELSE statement pop
 		{ $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
 	| 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 ) );
@@ -957,5 +954,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 ) );
@@ -965,9 +962,9 @@
 
 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
@@ -1030,11 +1027,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 ); }
@@ -1265,5 +1262,5 @@
 
 declaration_list_opt:									// used at beginning of switch statement
-	pop	// empty
+	// empty
 		{ $$ = nullptr; }
 	| declaration_list
@@ -1272,18 +1269,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 ); }
 	;
@@ -1305,6 +1302,6 @@
 
 declaration:											// old & new style declarations
-	c_declaration pop ';'
-	| cfa_declaration pop ';'							// CFA
+	c_declaration ';'
+	| cfa_declaration ';'								// CFA
 	| static_assert
 	;
@@ -1414,15 +1411,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 ) );
 		}
@@ -1435,25 +1432,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 );
 		}
@@ -1582,6 +1579,6 @@
 
 forall:
-	FORALL '(' push type_parameter_list pop ')'					// CFA
-		{ $$ = DeclarationNode::newForall( $4 ); }
+	FORALL '(' type_parameter_list ')'					// CFA
+		{ $$ = DeclarationNode::newForall( $3 ); }
 	;
 
@@ -2175,5 +2172,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 ); }
@@ -2211,6 +2208,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; }
 	;
 
@@ -2244,19 +2241,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 ); }
 	;
 
@@ -2296,8 +2293,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; }
 	;
@@ -2321,9 +2319,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
@@ -2334,7 +2336,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() );
@@ -2343,11 +2345,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() );
@@ -2356,5 +2358,5 @@
  			xxx = false;
 			delete $1;
-			$$ = $5;
+			$$ = $4;
 		}
 	| declaration_qualifier_list type_qualifier_list
@@ -2363,7 +2365,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() );
@@ -2374,5 +2376,5 @@
 			delete $1;
 			delete $2;
-			$$ = $6;
+			$$ = $5;
 		}
 	;
@@ -2387,5 +2389,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 ); }
 	;
@@ -2427,5 +2429,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 );
@@ -2433,11 +2435,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 ); }
 	;
@@ -2684,5 +2686,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; }
@@ -3174,7 +3176,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; }
 	;
