fixing include bug (only ocured for includes in main program file).
authormario
Thu, 01 Nov 2007 20:58:38 +0100
changeset 76 ec7799ec929b
parent 75 0e381bdb8888
child 77 fe4ecf7efa79
fixing include bug (only ocured for includes in main program file).
stage1_2/iec.flex
--- a/stage1_2/iec.flex	Thu Nov 01 09:42:33 2007 +0100
+++ b/stage1_2/iec.flex	Thu Nov 01 20:58:38 2007 +0100
@@ -769,8 +769,15 @@
 			}
 
 
-<<EOF>>			{
-			  if (--include_stack_ptr < 0) {
+<<EOF>>			{     /* NOTE: We must not change the value of include_stack_ptr
+			       *       just yet. We must only decrement it if we are NOT
+			       *       at the end of the main file.
+			       *       If we have finished parsing the main file, then we
+			       *       must leave include_stack_ptr at 0, in case the 
+			       *       parser is called once again with a new file.
+			       *       (In fact, we currently do just that!)
+			       */
+			  if (include_stack_ptr == 0) {
 			      /* yyterminate() terminates the scanner and returns a 0 to the 
 			       * scanner's  caller, indicating "all done".
 			       *	
@@ -782,6 +789,7 @@
 			    yyterminate();
 			  }      
  else {
+			    --include_stack_ptr;	
 			    yy_delete_buffer(YY_CURRENT_BUFFER);
 			    yy_switch_to_buffer((include_stack[include_stack_ptr]).buffer_state);
 			    yylineno = include_stack[include_stack_ptr].lineno;