Mercurial > hg > octave-nkf
changeset 1229:7d7c3eaa1d3b
[project @ 1995-04-10 01:04:13 by jwe]
author | jwe |
---|---|
date | Mon, 10 Apr 1995 01:04:46 +0000 |
parents | 38b876e46ff6 |
children | 92609e161b29 |
files | src/parse.y src/pt-exp-base.cc src/pt-exp-base.h |
diffstat | 3 files changed, 68 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parse.y +++ b/src/parse.y @@ -28,7 +28,7 @@ #define YYDEBUG 1 #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <strstream.h> @@ -151,7 +151,7 @@ // Make an expression that handles assignment of multiple values. static tree_expression *make_multi_val_ret - (tree_expression *rhs, int l = -1, int c = -1); + (tree_matrix *m, tree_expression *rhs, int l = -1, int c = -1); // Make an index expression. static tree_index_expression *make_index_expression @@ -628,6 +628,18 @@ $$ = new tree_for_command ($2, $4, $6, $1->line (), $1->column ()); } + | FOR '[' screwed_again matrix_row SCREW_TWO '=' + expression optsep opt_list END + { + if (check_end ($10, token::for_end)) + ABORT_PARSE; + looping--; + tree_matrix *tmp = ml.pop (); + tmp = tmp->reverse (); + tree_return_list *id_list = tmp->to_return_list (); + $$ = new tree_for_command (id_list, $7, $9, + $1->line (), $1->column ()); + } | BREAK { if (! (looping || defining_func)) @@ -722,8 +734,10 @@ } | '[' screwed_again matrix_row SCREW_TWO '=' expression { - $$ = make_multi_val_ret ($6, $5->line (), $5->column ()); - + tree_matrix *tmp = ml.pop (); + tmp = tmp->reverse (); + $$ = make_multi_val_ret (tmp, $6, $5->line (), + $5->column ()); if (! $$) ABORT_PARSE; } @@ -1552,7 +1566,7 @@ // Make an expression that handles assignment of multiple values. static tree_expression * -make_multi_val_ret (tree_expression *rhs, int l, int c) +make_multi_val_ret (tree_matrix *m, tree_expression *rhs, int l, int c) { // Convert the matrix list to a list of identifiers. If that fails, // we can abort here, without losing anything -- no other possible @@ -1563,11 +1577,7 @@ maybe_screwed_again--; - tree_matrix *tmp = ml.pop (); - - tmp = tmp->reverse (); - - tree_return_list *id_list = tmp->to_return_list (); + tree_return_list *id_list = m->to_return_list (); if (id_list) { @@ -1585,7 +1595,8 @@ if (rhs->is_multi_val_ret_expression ()) { tree_multi_val_ret *t = (tree_multi_val_ret *) rhs; - retval = new tree_multi_assignment_expression (id_list, t, l, c); + retval = new tree_multi_assignment_expression (id_list, t, + 0, l, c); } else yyerror ("RHS must be an expression that returns multiple values");
--- a/src/pt-exp-base.cc +++ b/src/pt-exp-base.cc @@ -634,6 +634,20 @@ return tree_constant (); } +// Used internally. + +tree_constant +tree_oct_obj::eval (int print) +{ + return values(0); +} + +Octave_object +tree_oct_obj::eval (int print, int nargout, const Octave_object& args) +{ + return values; +} + // A base class for objects that can be evaluated with argument lists. tree_constant @@ -1984,7 +1998,9 @@ tree_multi_assignment_expression::~tree_multi_assignment_expression (void) { - delete lhs; + if (! preserve) + delete lhs; + delete rhs; }
--- a/src/pt-exp-base.h +++ b/src/pt-exp-base.h @@ -205,6 +205,30 @@ const Octave_object& args) = 0; }; +// Used internally. + +class +tree_oct_obj : public tree_multi_val_ret +{ +public: + tree_oct_obj (int l = -1, int c = -1) : tree_multi_val_ret (l, c) { } + + tree_oct_obj (const Octave_object& v, int l = -1, int c = -1) + : tree_multi_val_ret (l, c) + { + values = v; + } + + tree_constant eval (int print); + + Octave_object eval (int print, int nargout, const Octave_object& args); + + void print_code (ostream& os) { } + +private: + Octave_object values; +}; + // A base class for objects that can be evaluated with argument lists. class @@ -676,20 +700,23 @@ tree_multi_assignment_expression : public tree_multi_val_ret { public: - tree_multi_assignment_expression (int l = -1, int c = -1) + tree_multi_assignment_expression (int plhs = 0, int l = -1, int c = -1) : tree_multi_val_ret (l, c) { etype = tree_expression::multi_assignment; + preserve = plhs; lhs = 0; rhs = 0; } tree_multi_assignment_expression (tree_return_list *lst, tree_multi_val_ret *r, + int plhs = 0, int l = -1, int c = -1) : tree_multi_val_ret (l, c) { etype = tree_expression::multi_assignment; + preserve = plhs; lhs = lst; rhs = r; } @@ -708,6 +735,7 @@ void print_code (ostream& os); private: + int preserve; tree_return_list *lhs; tree_multi_val_ret *rhs; };