# HG changeset patch # User John W. Eaton # Date 1217524274 14400 # Node ID ff9e7873f8ea2008610dfcb93b820757e320ccc3 # Parent ea3cd9791703b00e36994e3f55eccd2e176d139d improve handling of command-style names in matrix_or_assign_lhs context diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2008-07-31 John W. Eaton + + * 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 * ov-intx.h, ov.cc: Style fixes. diff --git a/src/lex.h b/src/lex.h --- a/src/lex.h +++ b/src/lex.h @@ -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 pending_local_variables; + private: lexical_feedback (const lexical_feedback&); diff --git a/src/lex.l b/src/lex.l --- a/src/lex.l +++ b/src/lex.l @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/src/parse.y b/src/parse.y --- a/src/parse.y +++ b/src/parse.y @@ -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::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 (); } ;