comparison src/lex.l @ 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 cce16b4e0970
children 0ef13e15319b
comparison
equal deleted inserted replaced
8000:ea3cd9791703 8001:ff9e7873f8ea
37 #endif 37 #endif
38 38
39 #include <cctype> 39 #include <cctype>
40 #include <cstring> 40 #include <cstring>
41 41
42 #include <set>
42 #include <sstream> 43 #include <sstream>
43 #include <string> 44 #include <string>
44 #include <stack> 45 #include <stack>
45 46
46 #ifdef HAVE_UNISTD_H 47 #ifdef HAVE_UNISTD_H
1201 } 1202 }
1202 1203
1203 static bool 1204 static bool
1204 is_variable (const std::string& name) 1205 is_variable (const std::string& name)
1205 { 1206 {
1206 return symbol_table::is_variable (name); 1207 return (symbol_table::is_variable (name)
1207 } 1208 || (lexer_flags.pending_local_variables.find (name)
1208 1209 != lexer_flags.pending_local_variables.end ()));
1209 static void 1210 }
1211
1212 void
1210 force_local_variable (const std::string& name) 1213 force_local_variable (const std::string& name)
1211 { 1214 {
1212 octave_value& val = symbol_table::varref (name); 1215 octave_value& val = symbol_table::varref (name);
1213 1216
1214 if (! val.is_defined ()) 1217 if (! val.is_defined ())
2492 if (is_command_name (tok) && ! is_variable (tok)) 2495 if (is_command_name (tok) && ! is_variable (tok))
2493 { 2496 {
2494 if (next_tok_is_eq 2497 if (next_tok_is_eq
2495 || lexer_flags.looking_at_return_list 2498 || lexer_flags.looking_at_return_list
2496 || (lexer_flags.looking_at_parameter_list 2499 || (lexer_flags.looking_at_parameter_list
2497 && ! lexer_flags.looking_at_initializer_expression) 2500 && ! lexer_flags.looking_at_initializer_expression))
2498 || lexer_flags.looking_at_matrix_or_assign_lhs)
2499 { 2501 {
2500 force_local_variable (tok); 2502 force_local_variable (tok);
2503 }
2504 else if (lexer_flags.looking_at_matrix_or_assign_lhs)
2505 {
2506 lexer_flags.pending_local_variables.insert (tok);
2501 } 2507 }
2502 else if (! (next_tok_is_paren || lexer_flags.looking_at_object_index)) 2508 else if (! (next_tok_is_paren || lexer_flags.looking_at_object_index))
2503 { 2509 {
2504 BEGIN (COMMAND_START); 2510 BEGIN (COMMAND_START);
2505 } 2511 }
2587 // Not initially looking at indirect references. 2593 // Not initially looking at indirect references.
2588 looking_at_indirect_ref = false; 2594 looking_at_indirect_ref = false;
2589 2595
2590 // Quote marks strings intially. 2596 // Quote marks strings intially.
2591 quote_is_transpose = false; 2597 quote_is_transpose = false;
2598
2599 // Set of identifiers that might be local variable names is empty.
2600 pending_local_variables.clear ();
2592 } 2601 }
2593 2602
2594 bool 2603 bool
2595 is_keyword (const std::string& s) 2604 is_keyword (const std::string& s)
2596 { 2605 {