changeset 4240:8627d992beb8

[project @ 2002-12-25 23:07:03 by jwe]
author jwe
date Wed, 25 Dec 2002 23:07:03 +0000
parents 90db7796adc2
children 71209cc7ad4a
files src/ChangeLog src/lex.h src/lex.l src/parse.y
diffstat 4 files changed, 60 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Dec 25 21:47:43 2002 +0000
+++ b/src/ChangeLog	Wed Dec 25 23:07:03 2002 +0000
@@ -1,5 +1,20 @@
 2002-12-25  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* parse.y (function_end): If parsing a nested function, set
+	lexer_flags.parsing_nested_function to -1.
+	(frob_function): If lexer_flags.parsing_nested_function is
+	negative, set it to zero.
+	* lex.h (lexical_feedback::parsing_nested_function): Now int.
+	Change uses as needed.
+
+	* lex.l (NESTED_FUNCTION_BEGIN): Rename from NESTED_FUNCTION_START.
+	Now an exclusive start state.
+	(NESTED_FUNCTION_END): New exclusive start state.
+	(is_keyword): When matching a new function keyword in a nested
+	function context, explicitly return END and set start state to
+	NESTED_FUNCTION_END.
+	(.): Accept EOF here too.
+
 	* variables.cc (link_to_builtin_or_function): Maybe prepend parent
 	function name symbol name.
 
--- a/src/lex.h	Wed Dec 25 21:47:43 2002 +0000
+++ b/src/lex.h	Wed Dec 25 23:07:03 2002 +0000
@@ -186,8 +186,11 @@
   // Should only matter if defining_func is also TRUE.
   bool parsed_function_name;
 
-  // TRUE means that we're parsing a nested function definition.
-  bool parsing_nested_function;
+  // Are we parsing a nested function?
+  //   1 ==> Yes.
+  //   0 ==> No.
+  //  -1 ==> Yes, but it is the last one because we have seen EOF.
+  int parsing_nested_function;
 
   // TRUE means we've seen something that means we must be past the
   // range part of a plot command.
--- a/src/lex.l	Wed Dec 25 21:47:43 2002 +0000
+++ b/src/lex.l	Wed Dec 25 23:07:03 2002 +0000
@@ -22,7 +22,9 @@
 
 %s COMMAND_START
 %s MATRIX_START
-%s NESTED_FUNCTION_START
+
+%x NESTED_FUNCTION_END
+%x NESTED_FUNCTION_BEGIN
 
 %{
 #ifdef HAVE_CONFIG_H
@@ -241,8 +243,15 @@
 NUMBER	(({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+))
 %%
 
-<NESTED_FUNCTION_START>{} {
+<NESTED_FUNCTION_END>. {
+    BEGIN NESTED_FUNCTION_BEGIN;
+    unput (yytext[0]);
+    return ';';
+  }
+
+<NESTED_FUNCTION_BEGIN>. {
     BEGIN 0;
+    unput (yytext[0]);
     prep_for_nested_function ();
     return FCN;
   }
@@ -781,15 +790,20 @@
 %}
 
 . {
-    current_input_column++;
-
-    // EOF can't happen here (we catch it above).
-
-    error ("invalid character `%s' (ASCII %d) near line %d, column %d",
-	   undo_string_escape (yytext[0]), static_cast<int> (yytext[0]),
-	   input_line_number, current_input_column);
-
-    return LEXICAL_ERROR;
+    // EOF happens here if we are parsing nested functions.
+
+    if (yytext[0] != EOF)
+      {
+	current_input_column++;
+
+	error ("invalid character `%s' (ASCII %d) near line %d, column %d",
+	       undo_string_escape (yytext[0]), static_cast<int> (yytext[0]),
+	       input_line_number, current_input_column);
+
+	return LEXICAL_ERROR;
+      }
+    else
+      TOK_RETURN (END_OF_INPUT);
   }
 
 %%
@@ -1083,8 +1097,10 @@
 static void
 prep_for_nested_function (void)
 {
-  lexer_flags.parsing_nested_function = true;
+  lexer_flags.parsing_nested_function = 1;
   prep_for_function ();
+  // We're still only expecting one end token for this set of functions.
+  end_tokens_expected--;
   yylval.tok_val = new token (input_line_number, current_input_column);
   token_stack.push (yylval.tok_val);
 }
@@ -1246,15 +1262,19 @@
 	      {
 		if (reading_fcn_file)
 		  {
-
 		    if (lexer_flags.parsing_nested_function)
 		      {
-			BEGIN NESTED_FUNCTION_START;
+			BEGIN NESTED_FUNCTION_END;
+
 			yylval.tok_val = new token (token::function_end, l, c);
+			token_stack.push (yylval.tok_val);
+
+			return END;
 		      }
 		    else
 		      {
 			prep_for_nested_function ();
+
 			return FCN;
 		      }
 		  }
@@ -2619,7 +2639,7 @@
   beginning_of_function = false;
   defining_func = false;
   parsed_function_name = false;
-  parsing_nested_function = false;
+  parsing_nested_function = 0;
 
   // Not parsing a function return or parameter list.
   looking_at_return_list = false;
--- a/src/parse.y	Wed Dec 25 21:47:43 2002 +0000
+++ b/src/parse.y	Wed Dec 25 23:07:03 2002 +0000
@@ -1294,7 +1294,8 @@
 		  }
 		| END_OF_INPUT
 		  {
-		    lexer_flags.parsing_nested_function = false;
+		    if (lexer_flags.parsing_nested_function)
+		      lexer_flags.parsing_nested_function = -1;
 
 		    if (! (reading_fcn_file || reading_script_file
 			   || get_input_from_eval_string))
@@ -2595,6 +2596,9 @@
 
   help_buf.resize (0);
 
+  if (lexer_flags.parsing_nested_function < 0)
+    lexer_flags.parsing_nested_function = 0;
+  
   return fcn;
 }