Mercurial > hg > octave-nkf
changeset 16286:f58257a6d18c classdef
maint: periodic merge of default to classdef
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Mar 2013 18:24:50 -0400 |
parents | 82ff1c5bbff0 (current diff) 3389152014ca (diff) |
children | bde729ba8381 |
files | libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.in.yy |
diffstat | 5 files changed, 69 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -521,8 +521,6 @@ int handle_close_bracket (int bracket_type); - bool next_token_can_follow_bin_op (void); - bool looks_like_command_arg (void); int handle_superclass_identifier (void);
--- a/libinterp/parse-tree/lex.ll +++ b/libinterp/parse-tree/lex.ll @@ -794,7 +794,7 @@ return curr_lexer->count_token_internal (retval); } else - return curr_lexer->count_token (QUOTE); + return curr_lexer->count_token (HERMITIAN); } } else @@ -808,7 +808,7 @@ return curr_lexer->count_token_internal (retval); } else - return curr_lexer->count_token (QUOTE); + return curr_lexer->count_token (HERMITIAN); } } } @@ -1429,30 +1429,6 @@ return retval; } -class -flex_stream_reader : public stream_reader -{ -public: - flex_stream_reader (octave_lexer *l, char *buf_arg) - : stream_reader (), lexer (l), buf (buf_arg) - { } - - int getc (void) { return lexer->text_yyinput (); } - int ungetc (int c) { lexer->xunput (c, buf); return 0; } - -private: - - // No copying! - - flex_stream_reader (const flex_stream_reader&); - - flex_stream_reader& operator = (const flex_stream_reader&); - - octave_lexer *lexer; - - char *buf; -}; - lexical_feedback::~lexical_feedback (void) { tokens.clear (); @@ -2442,35 +2418,6 @@ } bool -octave_lexer::next_token_can_follow_bin_op (void) -{ - std::stack<char> buf; - - int c = EOF; - - // Skip whitespace in current statement on current line - while (true) - { - c = text_yyinput (); - - buf.push (c); - - if (match_any (c, ",;\n") || (c != ' ' && c != '\t')) - break; - } - - // Restore input. - while (! buf.empty ()) - { - xunput (buf.top ()); - - buf.pop (); - } - - return (isalnum (c) || match_any (c, "!\"'(-[_{~")); -} - -bool octave_lexer::looks_like_command_arg (void) { bool space_before = space_follows_previous_token (); @@ -2773,7 +2720,7 @@ case ELEFTDIV: std::cerr << "ELEFTDIV\n"; break; case EPLUS: std::cerr << "EPLUS\n"; break; case EMINUS: std::cerr << "EMINUS\n"; break; - case QUOTE: std::cerr << "QUOTE\n"; break; + case HERMITIAN: std::cerr << "HERMITIAN\n"; break; case TRANSPOSE: std::cerr << "TRANSPOSE\n"; break; case PLUS_PLUS: std::cerr << "PLUS_PLUS\n"; break; case MINUS_MINUS: std::cerr << "MINUS_MINUS\n"; break;
--- a/libinterp/parse-tree/oct-parse.in.yy +++ b/libinterp/parse-tree/oct-parse.in.yy @@ -228,7 +228,7 @@ %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT %token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV EPLUS EMINUS -%token <tok_val> QUOTE TRANSPOSE +%token <tok_val> HERMITIAN TRANSPOSE %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW %token <tok_val> NUM IMAG_NUM %token <tok_val> STRUCT_ELT @@ -323,7 +323,7 @@ %left '-' '+' EPLUS EMINUS %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV %right UNARY EXPR_NOT -%left POW EPOW QUOTE TRANSPOSE +%left POW EPOW HERMITIAN TRANSPOSE %right PLUS_PLUS MINUS_MINUS %left '(' '.' '{' @@ -610,8 +610,8 @@ { $$ = curr_parser.make_index_expression ($1, 0, '{'); } | oper_expr '{' arg_list '}' { $$ = curr_parser.make_index_expression ($1, $3, '{'); } - | oper_expr QUOTE - { $$ = curr_parser.make_postfix_op (QUOTE, $1, $2); } + | oper_expr HERMITIAN + { $$ = curr_parser.make_postfix_op (HERMITIAN, $1, $2); } | oper_expr TRANSPOSE { $$ = curr_parser.make_postfix_op (TRANSPOSE, $1, $2); } | oper_expr indirect_ref_op STRUCT_ELT @@ -2208,7 +2208,7 @@ switch (op) { - case QUOTE: + case HERMITIAN: t = octave_value::op_hermitian; break; @@ -3211,29 +3211,46 @@ if (e->is_constant ()) { - bison_error ("invalid empty LHS in [] = ... assignment"); + octave_value ov = e->rvalue1 (); + + if (ov.is_empty ()) + bison_error ("invalid empty left hand side of assignment"); + else + bison_error ("invalid constant left hand side of assignment"); + delete e; } - else if (e->is_matrix ()) - { - tree_matrix *mat = dynamic_cast<tree_matrix *> (e); - - if (mat && mat->size () == 1) - { - retval = mat->front (); - mat->pop_front (); - delete e; - } - else - { - bison_error ("invalid LHS in '[LHS] = ...' assignment"); - delete e; - } - } else { - retval = new tree_argument_list (e); - retval->mark_as_simple_assign_lhs (); + bool is_simple_assign = true; + + tree_argument_list *tmp = 0; + + if (e->is_matrix ()) + { + tree_matrix *mat = dynamic_cast<tree_matrix *> (e); + + if (mat && mat->size () == 1) + { + tmp = mat->front (); + mat->pop_front (); + delete e; + is_simple_assign = false; + } + } + else + tmp = new tree_argument_list (e); + + if (tmp && tmp->is_valid_lvalue_list ()) + retval = tmp; + else + { + bison_error ("invalid left hand side of assignment"); + delete tmp; + } + + if (retval && is_simple_assign) + retval->mark_as_simple_assign_lhs (); } return retval;
--- a/libinterp/parse-tree/pt-arg-list.cc +++ b/libinterp/parse-tree/pt-arg-list.cc @@ -99,6 +99,29 @@ return true; } +bool +tree_argument_list::is_valid_lvalue_list (void) const +{ + bool retval = true; + + for (const_iterator p = begin (); p != end (); p++) + { + tree_expression *elt = *p; + + // There is no need for a separate check for the magic "~" because + // it represented by tree_black_hole, and that is derived from + // tree_identifier. + + if (! (elt->is_identifier () || elt->is_index_expression ())) + { + retval = false; + break; + } + } + + return retval; +} + static const octave_value *indexed_object = 0; static int index_position = 0; static int num_indices = 0;
--- a/libinterp/parse-tree/pt-arg-list.h +++ b/libinterp/parse-tree/pt-arg-list.h @@ -77,6 +77,8 @@ bool all_elements_are_constant (void) const; + bool is_valid_lvalue_list (void) const; + octave_value_list convert_to_const_vector (const octave_value *object = 0); std::list<octave_lvalue> lvalue_list (void);