# HG changeset patch # User jwe # Date 861873013 0 # Node ID 5c1b9e545dd1d776c56d6a69aca9b05b080d1a8c # Parent b4a9f014a8eac82d3b6959f1056fa238f4a47a18 [project @ 1997-04-24 09:07:39 by jwe] diff --git a/src/lex.h b/src/lex.h --- a/src/lex.h +++ b/src/lex.h @@ -122,10 +122,10 @@ // Brace level count. int braceflag; - // Nonzero means we're in the middle of defining a loop. + // TRUE means we're in the middle of defining a loop. int looping; - // Nonzero means we think we are looking at the beginning of a + // TRUE means we think we are looking at the beginning of a // function definition. bool beginning_of_function; @@ -133,51 +133,51 @@ // `title', and `with' keywords. bool cant_be_identifier; - // Nonzero means that we should convert spaces to a comma inside a + // TRUE means that we should convert spaces to a comma inside a // matrix definition. bool convert_spaces_to_comma; - // Nonzero means we're in the middle of defining a function. + // TRUE means we're in the middle of defining a function. bool defining_func; - // Nonzero means we're parsing the return list for a function. + // TRUE means we're parsing the return list for a function. bool looking_at_return_list; - // Nonzero means we're parsing the parameter list for a function. + // TRUE means we're parsing the parameter list for a function. bool looking_at_parameter_list; // GAG. Stupid kludge so that [[1,2][3,4]] will work. bool do_comma_insert; - // Nonzero means we think we are looking at a set command. + // TRUE means we think we are looking at a set command. bool doing_set; - // Nonzero means we're looking at the range part of a plot command. + // TRUE means we're looking at the range part of a plot command. bool in_plot_range; - // Nonzero means we're looking at the using part of a plot command. + // TRUE means we're looking at the using part of a plot command. bool in_plot_using; - // Nonzero means we're looking at the style part of a plot command. + // TRUE means we're looking at the style part of a plot command. bool in_plot_style; - // Nonzero means we're looking at an indirect reference to a + // TRUE means we're looking at an indirect reference to a // structure element. bool looking_at_indirect_ref; - // Nonzero means we need to do some extra lookahead to avoid being - // screwed by bogus function syntax. - bool maybe_screwed; - - // Nonzero means we need to do some extra lookahead to avoid being + // TRUE means we need to do some extra lookahead to avoid being // screwed by bogus function syntax. int maybe_screwed_again; - // Nonzero means we've seen something that means we must be past the + // TRUE means that we've already seen the name of this function. + // Should only matter if defining_func is also TRUE. + bool parsed_function_name; + + // TRUE means we've seen something that means we must be past the // range part of a plot command. bool past_plot_range; - // Nonzero means we're working on a plot command. + // TRUE means we're working on a plot command. bool plotting; // Return transpose or start a string? diff --git a/src/lex.l b/src/lex.l --- a/src/lex.l +++ b/src/lex.l @@ -572,8 +572,8 @@ "==" { BIN_OP_RETURN (EXPR_EQ, false); } {NOTEQ} { BIN_OP_RETURN (EXPR_NE, false); } ">=" { BIN_OP_RETURN (EXPR_GE, false); } +"&" { BIN_OP_RETURN (EXPR_AND, false); } "|" { BIN_OP_RETURN (EXPR_OR, false); } -"&" { BIN_OP_RETURN (EXPR_AND, false); } "<" { BIN_OP_RETURN (EXPR_LT, false); } ">" { BIN_OP_RETURN (EXPR_GT, false); } "*" { BIN_OP_RETURN ('*', false); } @@ -583,8 +583,8 @@ "," { BIN_OP_RETURN (',', true); } {POW} { BIN_OP_RETURN (POW, false); } "=" { BIN_OP_RETURN ('=', true); } +"&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } "||" { BIN_OP_RETURN (EXPR_OR_OR, false); } -"&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } {NOT} { if (lexer_flags.plotting && ! lexer_flags.in_plot_range) @@ -627,6 +627,17 @@ TOK_RETURN ('.'); } +"+=" { BIN_OP_RETURN (ADD_EQ, false); } +"-=" { BIN_OP_RETURN (SUB_EQ, false); } +"*=" { BIN_OP_RETURN (MUL_EQ, false); } +"/=" { BIN_OP_RETURN (DIV_EQ, false); } +".+=" { BIN_OP_RETURN (ADD_EQ, false); } +".-=" { BIN_OP_RETURN (SUB_EQ, false); } +".*=" { BIN_OP_RETURN (EMUL_EQ, false); } +"./=" { BIN_OP_RETURN (EDIV_EQ, false); } +"&=" { BIN_OP_RETURN (AND_EQ, false); } +"|=" { BIN_OP_RETURN (OR_EQ, false); } + %{ // Unrecognized input is a lexical error. %} @@ -926,7 +937,7 @@ } } -// Handle keywords. Could probably be more efficient... +// Handle keywords. static int is_keyword (const string& s) @@ -1048,11 +1059,16 @@ } else { + // Prepare for local symbols. + tmp_local_sym_tab = new symbol_table (); - curr_sym_tab = tmp_local_sym_tab; + + promptflag--; + lexer_flags.defining_func = true; - promptflag--; + lexer_flags.parsed_function_name = false; lexer_flags.beginning_of_function = true; + if (! (reading_fcn_file || reading_script_file)) input_line_number = 1; } @@ -1768,8 +1784,14 @@ // Make sure we put the return values of a function in the symbol // table that is local to the function. + // If we are defining a function and we have not seen the function + // name yet and the next token is `=', then this identifier must be + // the only return value for the function and it belongs in the + // local symbol table. + if (next_tok_is_eq - && lexer_flags.defining_func && lexer_flags.maybe_screwed) + && lexer_flags.defining_func + && ! lexer_flags.parsed_function_name) curr_sym_tab = tmp_local_sym_tab; // Kluge alert. @@ -1811,35 +1833,17 @@ lexer_flags.convert_spaces_to_comma = true; - // If we are defining a function and we have not seen the parameter - // list yet and the next token is `=', return a token that - // represents the only return value for the function. For example, - // - // function SCREW = f (args); - // - // The variable maybe_screwed is reset in parse.y. + if (! next_tok_is_eq) + { + lexer_flags.quote_is_transpose = true; - if (next_tok_is_eq) - { - current_input_column += yyleng; - if (lexer_flags.defining_func && lexer_flags.maybe_screwed) - return SCREW; - else - return NAME; + do_comma_insert_check (); + + maybe_unput_comma (spc_gobbled); } - // At this point, we are only dealing with identifiers that are not - // followed by `=' (if the next token is `=', there is no need to - // check to see if we should insert a comma (invalid syntax), or - // allow a following `'' to be treated as a transpose (the next - // token is `=', so it can't be `''. + current_input_column += yyleng; - lexer_flags.quote_is_transpose = true; - do_comma_insert_check (); - - maybe_unput_comma (spc_gobbled); - - current_input_column += yyleng; return NAME; } @@ -1905,6 +1909,7 @@ // Not initially defining a function. beginning_of_function = false; defining_func = false; + parsed_function_name = false; // Not parsing a function return or parameter list. looking_at_return_list = false; @@ -1930,7 +1935,6 @@ looking_at_indirect_ref = false; // Not initially screwed by `function [...] = f (...)' syntax. - maybe_screwed = false; maybe_screwed_again = 0; // Quote marks strings intially. @@ -1960,19 +1964,6 @@ "control auto-insertion of commas and semicolons in literal matrices"); } -// Maybe someday... -// -// "+=" return ADD_EQ; -// "-=" return SUB_EQ; -// "*=" return MUL_EQ; -// "/=" return DIV_EQ; -// "\\=" return LEFTDIV_EQ; -// ".+=" return ADD_EQ; -// ".-=" return SUB_EQ; -// ".*=" return EMUL_EQ; -// "./=" return EDIV_EQ; -// ".\\=" return ELEFTDIV_EQ; - /* ;;; Local Variables: *** ;;; mode: C++ *** diff --git a/src/oct-iostrm.h b/src/oct-iostrm.h --- a/src/oct-iostrm.h +++ b/src/oct-iostrm.h @@ -23,6 +23,8 @@ #if !defined (octave_octave_iostream_h) #define octave_octave_iostream_h 1 +#include + #include "oct-stream.h" class istream; diff --git a/src/oct-obj.h b/src/oct-obj.h --- a/src/oct-obj.h +++ b/src/oct-obj.h @@ -27,10 +27,11 @@ #pragma interface #endif +class string_vector; + #include #include "Array.h" -#include "str-vec.h" #include "ov.h" diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -36,6 +36,7 @@ #include "error.h" #include "oct-stream.h" +#include "oct-obj.h" #include "utils.h" // Possible values for conv_err: diff --git a/src/oct-stream.h b/src/oct-stream.h --- a/src/oct-stream.h +++ b/src/oct-stream.h @@ -23,18 +23,21 @@ #if !defined (octave_octave_stream_h) #define octave_octave_stream_h 1 -#include +class Matrix; +class string_vector; +class octave_value; +class octave_value_list; -#include -#include +class istream; +class ostream; +class ostrstream; + +#include #include "Array.h" #include "data-conv.h" #include "mach-info.h" -#include "oct-obj.h" -#include "str-vec.h" - struct scanf_format_elt {