Mercurial > hg > octave-lojdl
changeset 1491:893b416bb919
[project @ 1995-09-29 04:03:01 by jwe]
author | jwe |
---|---|
date | Fri, 29 Sep 1995 04:08:17 +0000 |
parents | 4d6c168ff235 |
children | af2d53865577 |
files | src/parse.y src/pt-cmd.cc src/pt-exp-base.cc src/pt-exp-base.h src/pt-misc.cc src/pt-misc.h |
diffstat | 6 files changed, 86 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parse.y +++ b/src/parse.y @@ -221,7 +221,9 @@ %token <tok_val> END %token <tok_val> PLOT %token <tok_val> TEXT STYLE -%token <tok_val> FOR WHILE IF ELSEIF ELSE BREAK CONTINUE FUNC_RET +%token <tok_val> FOR WHILE +%token <tok_val> IF ELSEIF ELSE +%token <tok_val> BREAK CONTINUE FUNC_RET %token <tok_val> UNWIND CLEANUP %token <tok_val> TRY CATCH %token <tok_val> GLOBAL
--- a/src/pt-cmd.cc +++ b/src/pt-cmd.cc @@ -142,50 +142,12 @@ if (error_state) return; + if (! expr) + panic_impossible (); + for (;;) { - int expr_value = 0; - if (! expr) - return; - tree_constant t1 = expr->eval (0); - - if (error_state) - { - eval_error (); - return; - } - - if (t1.rows () == 0 || t1.columns () == 0) - { - int flag = user_pref.propagate_empty_matrices; - if (flag < 0) - warning ("while: empty matrix used in conditional"); - else if (flag == 0) - { - ::error ("empty matrix used in while condition near line\ - %d, column %d", line (), column ()); - return; - } - t1 = tree_constant (0.0); - } - else if (! t1.is_scalar_type ()) - { - tree_constant t2 = t1.all (); - t1 = t2.all (); - } - - if (t1.is_real_scalar ()) - expr_value = (int) t1.double_value (); - else if (t1.is_complex_scalar ()) - expr_value = t1.complex_value () != 0.0; - else - { - ::error ("invalid type used in while condition near line %d,\ - column %d", line (), column ()); - return; - } - - if (expr_value) + if (expr->is_logically_true ("while")) { if (list) {
--- a/src/pt-exp-base.cc +++ b/src/pt-exp-base.cc @@ -181,6 +181,67 @@ // Expressions. +int +tree_expression::is_logically_true (const char *warn_for) +{ + int expr_value = 0; + + tree_constant t1 = eval (0); + + if (error_state) + { +// XXX FIXME XXX +// +// eval_error (); +// + return expr_value; + } + + if (t1.is_undefined ()) + { + ::error ("%s: undefined value used in conditional expression\ + near line %d, column %d", warn_for, line (), column ()); + return expr_value; + } + + if (t1.rows () == 0 || t1.columns () == 0) + { + int flag = user_pref.propagate_empty_matrices; + if (flag < 0) + warning ("%s: empty matrix used in conditional expression\ + near line %d, column %d", warn_for, line (), column ()); + else if (flag == 0) + { + ::error ("%s: empty matrix used in conditional expression\ + near line %d, column %d", warn_for, line (), column ()); + return expr_value; + } + t1 = 0.0; + } + else if (! t1.is_scalar_type ()) + { + tree_constant t2 = t1.all (); + if (! error_state) + t1 = t2.all (); + + if (error_state) + { + ::error ("%s: invalid type in conditional expression near\ + line %d, column %d", warn_for, line (), column ()); + return expr_value; + } + } + + if (t1.is_real_scalar ()) + expr_value = (int) t1.double_value (); + else if (t1.is_complex_scalar ()) + expr_value = t1.complex_value () != 0.0; + else + panic_impossible (); + + return expr_value; +} + tree_constant tree_expression::eval (int /* print */) {
--- a/src/pt-exp-base.h +++ b/src/pt-exp-base.h @@ -138,6 +138,8 @@ virtual int is_prefix_expression (void) const { return 0; } + virtual int is_logically_true (const char *); + virtual void mark_for_possible_ans_assign (void) { panic_impossible (); }
--- a/src/pt-misc.cc +++ b/src/pt-misc.cc @@ -510,57 +510,9 @@ // If. int -tree_if_clause::is_else_clause (void) -{ - return (! expr); -} - -int tree_if_clause::eval (void) { - if (expr) - { - tree_constant t1 = expr->eval (0); - - if (error_state || t1.is_undefined ()) - return 0; - - if (t1.rows () == 0 || t1.columns () == 0) - { - int flag = user_pref.propagate_empty_matrices; - if (flag < 0) - warning ("if: empty matrix used in conditional"); - else if (flag == 0) - { - ::error ("if: empty matrix used in conditional"); - return 0; - } - t1 = tree_constant (0.0); - } - else if (! t1.is_scalar_type ()) - { - tree_constant t2 = t1.all (); - t1 = t2.all (); - } - - int expr_value = 0; - - if (t1.is_real_scalar ()) - expr_value = (int) t1.double_value (); - else if (t1.is_complex_scalar ()) - expr_value = t1.complex_value () != 0.0; - else - error ("if: all (all (cond)) is not a scalar"); - - if (expr_value) - { - if (list) - list->eval (1); - - return 1; - } - } - else + if (is_else_clause () || expr->is_logically_true ("if")) { if (list) list->eval (1);
--- a/src/pt-misc.h +++ b/src/pt-misc.h @@ -313,23 +313,24 @@ tree_if_clause : public tree_print_code { public: - tree_if_clause (void) + tree_if_clause (void) : tree_print_code () { expr = 0; list = 0; } - tree_if_clause (tree_statement_list *l) - { - expr = 0; - list = l; - } + tree_if_clause (tree_statement_list *l) : tree_print_code () + { + expr = 0; + list = l; + } tree_if_clause (tree_expression *e, tree_statement_list *l) - { - expr = e; - list = l; - } + : tree_print_code () + { + expr = e; + list = l; + } ~tree_if_clause (void) { @@ -337,7 +338,10 @@ delete list; } - int is_else_clause (void); + int is_else_clause (void) + { + return ! expr; + } int eval (void);