changeset 8001:ff9e7873f8ea

improve handling of command-style names in matrix_or_assign_lhs context
author John W. Eaton <jwe@octave.org>
date Thu, 31 Jul 2008 13:11:14 -0400
parents ea3cd9791703
children 30f560a5fbc3
files src/ChangeLog src/lex.h src/lex.l src/parse.y
diffstat 4 files changed, 43 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jul 31 05:53:02 2008 -0400
+++ b/src/ChangeLog	Thu Jul 31 13:11:14 2008 -0400
@@ -1,3 +1,18 @@
+2008-07-31  John W. Eaton  <jwe@octave.org>
+
+	* parse.y (assign_lhs): Call force_local_variable on all elements
+	of lexer_flags.pending_local_variables here, then clear the set.
+	(matrix): Clear lexer_flags.pending_local_variable here.
+	* lex.l (lexical_feedback::init): Clear it.
+	(force_local_variable): No longer static.
+	(is_variable): Also return true for names in the
+	lexer_flags.pending_local_variables.
+	(handle_identifier): If we are parsing a matrix list, mark
+	identifiers as pending local variables rather than forcing them to
+	be local variables immediately.
+	* lex.h (lexical_feedback::pending_local_variables): New data member.
+	(force_local_variable): Provide decl.
+
 2008-07-30  John W. Eaton  <jwe@octave.org>
 
 	* ov-intx.h, ov.cc: Style fixes.
--- a/src/lex.h	Thu Jul 31 05:53:02 2008 -0400
+++ b/src/lex.h	Thu Jul 31 13:11:14 2008 -0400
@@ -52,6 +52,8 @@
 
 extern void prep_lexer_for_script (void);
 
+extern void force_local_variable (const std::string& name);
+
 // For communication between the lexer and parser.
 
 class
@@ -127,6 +129,9 @@
   // Return transpose or start a string?
   bool quote_is_transpose;
 
+  // Set of identifiers that might be local variable names.
+  std::set<std::string> pending_local_variables;
+
 private:
 
   lexical_feedback (const lexical_feedback&);
--- a/src/lex.l	Thu Jul 31 05:53:02 2008 -0400
+++ b/src/lex.l	Thu Jul 31 13:11:14 2008 -0400
@@ -39,6 +39,7 @@
 #include <cctype>
 #include <cstring>
 
+#include <set>
 #include <sstream>
 #include <string>
 #include <stack>
@@ -1203,10 +1204,12 @@
 static bool
 is_variable (const std::string& name)
 {
-  return symbol_table::is_variable (name);
+  return (symbol_table::is_variable (name)
+	  || (lexer_flags.pending_local_variables.find (name)
+	      != lexer_flags.pending_local_variables.end ()));
 }
 
-static void
+void
 force_local_variable (const std::string& name)
 {
   octave_value& val = symbol_table::varref (name);
@@ -2494,11 +2497,14 @@
       if (next_tok_is_eq
 	  || lexer_flags.looking_at_return_list
 	  || (lexer_flags.looking_at_parameter_list
-	      && ! lexer_flags.looking_at_initializer_expression)
-	  || lexer_flags.looking_at_matrix_or_assign_lhs)
+	      && ! lexer_flags.looking_at_initializer_expression))
 	{
 	  force_local_variable (tok);
 	}
+      else if (lexer_flags.looking_at_matrix_or_assign_lhs)
+	{
+	  lexer_flags.pending_local_variables.insert (tok);
+	}
       else if (! (next_tok_is_paren || lexer_flags.looking_at_object_index))
 	{
 	  BEGIN (COMMAND_START);
@@ -2589,6 +2595,9 @@
 
   // Quote marks strings intially.
   quote_is_transpose = false;
+
+  // Set of identifiers that might be local variable names is empty.
+  pending_local_variables.clear ();
 }
 
 bool
--- a/src/parse.y	Thu Jul 31 05:53:02 2008 -0400
+++ b/src/parse.y	Thu Jul 31 13:11:14 2008 -0400
@@ -579,16 +579,19 @@
 		  {
 		    $$ = new tree_constant (octave_value (Matrix ()));
 		    lexer_flags.looking_at_matrix_or_assign_lhs = false;
+		    lexer_flags.pending_local_variables.clear ();
 		  }
 		| '[' ';' ']'
 		  {
 		    $$ = new tree_constant (octave_value (Matrix ()));
 		    lexer_flags.looking_at_matrix_or_assign_lhs = false;
+		    lexer_flags.pending_local_variables.clear ();
 		  }
 		| '[' matrix_rows ']'
 		  {
 		    $$ = finish_matrix ($2);
 		    lexer_flags.looking_at_matrix_or_assign_lhs = false;
+		    lexer_flags.pending_local_variables.clear ();
 		  }
 		;
 
@@ -835,6 +838,13 @@
 		  {
 		    $$ = $2;
 		    lexer_flags.looking_at_matrix_or_assign_lhs = false;
+		    for (std::set<std::string>::const_iterator p = lexer_flags.pending_local_variables.begin ();
+			 p != lexer_flags.pending_local_variables.end ();
+			 p++)
+		      {
+			force_local_variable (*p);
+		      }
+		    lexer_flags.pending_local_variables.clear ();
 		  }
 		;