diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h
index dace0465393914d2729f83de1b15dfa482937e87..bfc72f3921390a7194a53fdd8adf8bbd834906b3 100644
--- a/gcc/cobol/cbldiag.h
+++ b/gcc/cobol/cbldiag.h
@@ -105,7 +105,7 @@ template <typename LOC>
 static void
 location_dump( const char func[], int line, const char tag[], const LOC& loc) {
   extern int yy_flex_debug;
-  if( false && yy_flex_debug ) 
+  if( yy_flex_debug && getenv("update_location") ) 
     fprintf(stderr, "%s:%d: %s location (%d,%d) to (%d,%d)\n",
 	    func, line, tag, 
 	    loc.first_line, loc.first_column, loc.last_line, loc.last_column);
diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y
index 0493dfe5ebcff6bd368f0d659beb905b5bf5eed8..3f72dd7f70aae983516142232feef50df4d7f6cd 100644
--- a/gcc/cobol/cdf.y
+++ b/gcc/cobol/cdf.y
@@ -72,6 +72,7 @@ static int ydflex(void);
 
 const YYLTYPE& cobol_location();
 static YYLTYPE location_set( const YYLTYPE& loc );
+void input_file_status_notify();
 
 #define YYLLOC_DEFAULT(Current, Rhs, N) 				\
   do {									\
@@ -92,6 +93,7 @@ static YYLTYPE location_set( const YYLTYPE& loc );
 	  (Current).last_column  = YYRHSLOC (Rhs, 0).last_column;	\
         }                                                               \
       location_dump("cdf.c", __LINE__, "current", (Current));		\
+      input_file_status_notify();					\
       gcc_location_set( location_set(Current) );			\
   } while (0)
 
diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h
index c037625b6b35278776523da07ea21e827e6857d1..db9333b0d76ef269269770ef9693b4a7a4f7cad4 100644
--- a/gcc/cobol/parse_ante.h
+++ b/gcc/cobol/parse_ante.h
@@ -77,7 +77,8 @@ static size_t nparse_error = 0;
 
 size_t parse_error_inc() { return ++nparse_error; }
 size_t parse_error_count() { return nparse_error; }
-
+void input_file_status_notify();
+  
 #define YYLLOC_DEFAULT(Current, Rhs, N) 				\
   do {									\
       if (N)                                                            \
@@ -98,6 +99,7 @@ size_t parse_error_count() { return nparse_error; }
         }                                                               \
       location_dump("parse.c", __LINE__, "current", (Current));		\
       gcc_location_set( location_set(Current) );			\
+      input_file_status_notify();					\
   } while (0)
 
 int yylex(void);
diff --git a/gcc/cobol/scan.l b/gcc/cobol/scan.l
index 8f5454ca7042dac23a16fb7027370d2c004a9779..be2f630ced1078797db2b0b886aeaa6a53c76ccd 100644
--- a/gcc/cobol/scan.l
+++ b/gcc/cobol/scan.l
@@ -2103,19 +2103,12 @@ BASIS		{ yy_push_state(basis); return BASIS; }
 			if( yytext[0] != '\f' ) {
 			  dbgmsg("logic warning: filename was adjusted to %s", --filename);
 			}
-			cobol_filename(filename, 0);
-
-			if( yy_flex_debug ) dbgmsg("starting line %4d of %s",
-						   yylineno, filename);
-			parser_enter_file(filename);
+			input_file_status.enter(filename);
 		}
 
   {POP_FILE} 	{
 			yy_set_bol(true);
-			auto name = cobol_filename_restore();
-	   		if( yy_flex_debug ) dbgmsg("resuming line %4d of %s",
-						   yylineno, name? name : "<none>");
-			parser_leave_file();
+			input_file_status.leave();
 		}
 
   {LINE_DIRECTIVE} {	cobol_fileline_set(yytext); }
diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h
index 866fac1f45a1decc1a6ba0791f5bedcf2345ab99..74945a97a1694c8b8e42972f86b7eade9b4e6459 100644
--- a/gcc/cobol/scan_ante.h
+++ b/gcc/cobol/scan_ante.h
@@ -359,6 +359,58 @@ static void level_found() {
     yyless(n);					\
   } while(0)
 
+class enter_leave_t {
+  typedef void( parser_enter_file_f)(const char *filename);
+  typedef void (parser_leave_file_f)();
+  parser_enter_file_f *entering;
+  parser_leave_file_f *leaving;
+  const char *filename;
+
+ public:
+  enter_leave_t() : entering(NULL), leaving(NULL), filename(NULL) {}
+  enter_leave_t(  parser_enter_file_f *entering, const char *filename )
+    : entering(entering), leaving(NULL), filename(filename) {}
+  enter_leave_t(parser_leave_file_f *leaving)
+    : entering(NULL), leaving(leaving), filename(NULL) {}
+  
+  void notify() {
+    if( entering ) {
+      cobol_filename(filename, 0);
+      if( yy_flex_debug ) dbgmsg("starting line %4d of %s",
+				 yylineno, filename);
+      entering(filename);
+      gcc_assert(leaving == NULL);
+    }
+    if( leaving ) {
+      auto name = cobol_filename_restore();
+      if( yy_flex_debug ) dbgmsg("resuming line %4d of %s",
+				 yylineno, name? name : "<none>");
+      leaving();
+      gcc_assert(entering == NULL);
+    }
+  }
+};
+
+static class input_file_status_t {
+  std::queue <enter_leave_t> inputs;
+ public:
+  void enter(const char *filename) {
+    inputs.push( enter_leave_t(parser_enter_file, filename) );
+  }
+  void leave() {
+    inputs.push( parser_leave_file );
+  }
+  void notify() {
+    while( ! inputs.empty() ) {
+      auto enter_leave = inputs.front();
+      enter_leave.notify();
+      inputs.pop();
+    }
+  }
+} input_file_status;
+
+void input_file_status_notify() { input_file_status.notify(); }
+
 void cdf_location_set(YYLTYPE loc);
 
 static void
@@ -375,12 +427,8 @@ update_location() {
   }
 
   yylloc = loc;
-
   cdf_location_set(loc);
-
-  if( getenv(__func__) ) {
-    location_dump(__func__, __LINE__, "yylloc", yylloc);
-  }
+  location_dump(__func__, __LINE__, "yylloc", yylloc);
 }
 
 static void
@@ -410,9 +458,7 @@ trim_location( int nkeep) {
     yylloc.first_column = 1;
   }
 
-  if( getenv("update_location") ) {
-    location_dump(__func__, __LINE__, "yylloc", yylloc);
-  }
+  location_dump(__func__, __LINE__, "yylloc", yylloc);
 }
 
 static void
@@ -421,9 +467,7 @@ update_location_col( const char str[], int correction = 0) {
   if( col > 0 ) {
     yylloc.first_column = col;
   }
-  if( getenv("update_location") ) {
-    location_dump(__func__, __LINE__, "yylloc", yylloc);
-  }
+  location_dump(__func__, __LINE__, "yylloc", yylloc);
 }
     
 #define not_implemented(...) cbl_unimplemented_at(yylloc, __VA_ARGS__)
diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc
index 1507c13c37f02326778b0568b4440e894b631004..2dd65da4173c42f70bb890b0f9a1a523297f82d0 100644
--- a/gcc/cobol/util.cc
+++ b/gcc/cobol/util.cc
@@ -2005,9 +2005,7 @@ void
 gcc_location_set( const LOC& loc ) {
   token_location = linemap_line_start( line_table, loc.last_line, 80 );
   token_location = linemap_position_for_column( line_table, loc.first_column);
-  if( getenv(__func__) ) {
-    location_dump(__func__, __LINE__, "parser", loc);
-  }
+  location_dump(__func__, __LINE__, "parser", loc);
 }
 
 #ifdef NDEBUG