# HG changeset patch # User jwe # Date 780937934 0 # Node ID 6182de8cb3b7b161d657c13d30c4034ca4799c4b # Parent 46f6f6a4f5c647e8640f039a6973bf2045268775 [project @ 1994-09-30 15:09:36 by jwe] diff -r 46f6f6a4f5c6 -r 6182de8cb3b7 src/lex.l --- a/src/lex.l Fri Sep 30 15:05:10 1994 +0000 +++ b/src/lex.l Fri Sep 30 15:12:14 1994 +0000 @@ -685,6 +685,9 @@ in_plot_style = 0; doing_set = 0; +// Not initially looking at indirect references. + looking_at_indirect_ref = 0; + // Error may have occurred inside some parentheses or braces. in_brace_or_paren.clear (); @@ -1357,6 +1360,16 @@ static int handle_identifier (char *tok, int next_tok_is_eq) { +// If we are expecting a structure element, we just want to return +// TEXT_ID, which is a string that is also a valid identifier. + + if (looking_at_indirect_ref) + { + yylval.tok_val = new token (tok); + token_stack.push (yylval.tok_val); + TOK_RETURN (TEXT_ID); + } + // If we have a regular keyword, or a plot STYLE, return it. STYLE is // special only because it can't be followed by an identifier. @@ -1469,7 +1482,7 @@ int c1 = yyinput (); unput (c1); - int other_op = match_any (c1, ",;\n]"); + int other_op = match_any (c1, ".,;\n]"); int index_op = (c1 == '(' && (user_pref.commas_in_literal_matrix == 0 || ! spc_prev)); diff -r 46f6f6a4f5c6 -r 6182de8cb3b7 src/pt-const.cc --- a/src/pt-const.cc Fri Sep 30 15:05:10 1994 +0000 +++ b/src/pt-const.cc Fri Sep 30 15:12:14 1994 +0000 @@ -35,6 +35,13 @@ #include "error.h" #include "gripes.h" #include "user-prefs.h" +#include "oct-map.h" + +Octave_map +tree_constant::map_value (void) const +{ + return rep->map_value (); +} tree_constant::~tree_constant (void) { @@ -67,6 +74,170 @@ } #endif +// Simple assignment. + +tree_constant +tree_constant::operator = (const tree_constant& a) +{ + if (rep != a.rep) + { + if (--rep->count <= 0) + delete rep; + rep = a.rep; + rep->count++; + } + return *this; +} + +tree_constant +tree_constant::lookup_map_element (SLList& list) +{ + tree_constant retval; + + tree_constant_rep *tmp_rep = rep; + + Pix p = list.first (); + while (p) + { + char *elt = list (p); + + list.next (p); + + tree_constant tmp = tmp_rep->lookup_map_element (elt); + + if (error_state) + break; + + tmp_rep = tmp.rep; + + if (! p) + retval = tmp; + } + + return retval; +} + +// Simple structure assignment. + +void +tree_constant::make_unique (void) +{ + if (rep->count > 1) + { + --rep->count; + rep = new tree_constant_rep (*rep); + rep->count = 1; + } + + if (rep->is_map ()) + { + for (Pix p = rep->a_map->first (); p != 0; rep->a_map->next (p)) + { + rep->a_map->contents (p) . make_unique (); + } + } +} + +tree_constant::tree_constant_rep * +tree_constant::make_unique_map (void) +{ + if (! rep->is_map ()) + { + if (--rep->count <= 0) + delete rep; + + Octave_map m; + rep = new tree_constant_rep (m); + rep->count = 1; + } + + make_unique (); + + return rep; +} + +tree_constant +tree_constant::assign_map_element (SLList& list, tree_constant& rhs) +{ + tree_constant_rep *tmp_rep = make_unique_map (); + + if (rhs.is_map ()) + rhs.make_unique (); + + Pix p = list.first (); + while (p) + { + char *elt = list (p); + + list.next (p); + + tree_constant& tmp = tmp_rep->lookup_map_element (elt, 1); + + if (! p) + { + tmp = rhs; + return tmp; + } + + tmp_rep = tmp.make_unique_map (); + } + + return tree_constant (); +} + +// Indexed structure assignment. + +tree_constant +tree_constant::assign_map_element (SLList& list, tree_constant& rhs, + const Octave_object& args) +{ + tree_constant_rep *tmp_rep = make_unique_map (); + + if (rhs.is_map ()) + rhs.make_unique (); + + Pix p = list.first (); + while (p) + { + char *elt = list (p); + + list.next (p); + + tree_constant& tmp = tmp_rep->lookup_map_element (elt, 1); + + if (! p) + { + tmp.assign (rhs, args); + return tmp; + } + + tmp_rep = tmp.make_unique_map (); + } + + return tree_constant (); +} + +void +tree_constant::print_code (ostream& os) +{ + print_code_indent (os); + + if (in_parens) + os << "("; + + if (rep) + rep->print_code (os); + + if (in_parens) + os << ")"; +} + +void +gripe_wrong_type_arg (const char *name, const tree_constant& tc) +{ + error ("%s: wrong type argument `%s'", name, tc.type_as_string ()); +} + // Construct return vector of empty matrices. Return empty matrices // and/or gripe when appropriate. @@ -94,27 +265,6 @@ return retval; } -void -tree_constant::print_code (ostream& os) -{ - print_code_indent (os); - - if (in_parens) - os << "("; - - if (rep) - rep->print_code (os); - - if (in_parens) - os << ")"; -} - -void -gripe_wrong_type_arg (const char *name, const tree_constant& tc) -{ - error ("%s: wrong type argument `%s'", name, tc.type_as_string ()); -} - /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r 46f6f6a4f5c6 -r 6182de8cb3b7 src/pt-const.h --- a/src/pt-const.h Fri Sep 30 15:05:10 1994 +0000 +++ b/src/pt-const.h Fri Sep 30 15:12:14 1994 +0000 @@ -40,6 +40,7 @@ #include "oct-obj.h" class idx_vector; +class Octave_map; struct Mapper_fcn; @@ -123,6 +124,9 @@ tree_constant (const Range& r) : tree_fvc () { rep = new tree_constant_rep (r); rep->count = 1; } + tree_constant (const Octave_map& m) : tree_fvc () + { rep = new tree_constant_rep (m); rep->count = 1; } + tree_constant (tree_constant::magic_colon t) : tree_fvc () { tree_constant_rep::constant_type tmp; @@ -148,19 +152,11 @@ // Simple assignment. - tree_constant operator = (const tree_constant& a) - { - if (--rep->count <= 0 && rep != a.rep) - delete rep; - - rep = a.rep; - rep->count++; - return *this; - } + tree_constant operator = (const tree_constant& a); // Indexed assignment. - tree_constant assign (tree_constant& rhs, const Octave_object& args) + tree_constant assign (const tree_constant& rhs, const Octave_object& args) { if (rep->count > 1) { @@ -172,6 +168,15 @@ return *this; } +// Simple structure assignment. + + tree_constant assign_map_element (SLList& list, tree_constant& rhs); + +// Indexed structure assignment. + + tree_constant assign_map_element (SLList& list, tree_constant& rhs, + const Octave_object& args); + // Type. It would be nice to eliminate the need for this. int is_constant (void) const { return 1; } @@ -197,6 +202,7 @@ int is_complex_matrix (void) const { return rep->is_complex_matrix (); } int is_string (void) const { return rep->is_string (); } int is_range (void) const { return rep->is_range (); } + int is_map (void) const { return rep->is_map (); } int is_magic_colon (void) const { return rep->is_magic_colon (); } // Are any or all of the elements in this constant nonzero? @@ -264,6 +270,10 @@ Range range_value (void) const { return rep->range_value (); } + Octave_map map_value (void) const; + + tree_constant lookup_map_element (SLList& list); + ColumnVector vector_value (int force_string_conversion = 0, int force_vector_conversion = 0) const { return rep->vector_value (); } @@ -339,6 +349,16 @@ char *type_as_string (void) const { return rep->type_as_string (); } +// We really do need this, and it should be private: + +private: + + void make_unique (void); + + tree_constant_rep *make_unique_map (void); + +public: + // ------------------------------------------------------------------- // These may not need to be member functions.