Mercurial > hg > octave-lojdl
changeset 3388:42cb61dd0248
[project @ 1999-12-16 04:51:43 by jwe]
author | jwe |
---|---|
date | Thu, 16 Dec 1999 04:51:46 +0000 |
parents | eb4223985ca8 |
children | d91b8d83c4a2 |
files | scripts/ChangeLog scripts/control/analdemo.m scripts/control/syssub.m scripts/control/zp2ss.m scripts/finance/npv.m scripts/statistics/base/studentize.m scripts/statistics/base/values.m scripts/statistics/distributions/exponential_cdf.m scripts/statistics/distributions/poisson_cdf.m src/ChangeLog src/lex.l src/parse.y |
diffstat | 12 files changed, 149 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,13 +1,20 @@ 1999-12-15 John W. Eaton <jwe@bevo.che.wisc.edu> - * control/bddemo.m: Make it more likely to work with - whitespace_in_literal_matrix = "ignore". + * control/bddemo.m: Make it more likely to work with any value of + whitespace_in_literal_matrix. * control/analdemo.m: Ditto. * control/dgkfdemo.m: Ditto. * control/frdemo.m: Ditto. * control/sysrepdemo.m: Ditto. * control/moddemo.m: Ditto. + * control/zp2ss.m: Ditto. * control/zp2tf.m: Ditto. + * control/syssub.m: Ditto. + * finance/npv.m: Ditto. + * statistics/base/studentize.m: Ditto. + * statistics/base/values.m: Ditto. + * statistics/distributions/exponential_cdf.m: Ditto. + * statistics/distributions/poisson_cdf.m: Ditto. * control/dezero.m: Use toascii to convert string to ASCII value instead of multiplying it by 1.
--- a/scripts/control/analdemo.m +++ b/scripts/control/analdemo.m @@ -49,7 +49,7 @@ disp("Example #1, consider the discrete time state space system:\n"); a=[1, 5, -8.4; 1.2, -3, 5; 1, 7, 9] b=[1, 5; 2, 6; -4.4, 5] - c=[1 -1.5, 2; 6, -9.8, 1] + c=[1, -1.5, 2; 6, -9.8, 1] d=0 prompt disp("\nThe discrete controllability grammian is computed as follows:");
--- a/scripts/control/syssub.m +++ b/scripts/control/syssub.m @@ -100,7 +100,7 @@ eyin = eye(mg); eyout = eye(pg); - sys = sysscale(sys,[eyout -eyout],[eyin;eyin],Gout,Gin); + sys = sysscale (sys, [eyout, -eyout], [eyin; eyin], Gout, Gin); else ## multiple systems (or a single system); combine together one by one
--- a/scripts/control/zp2ss.m +++ b/scripts/control/zp2ss.m @@ -112,17 +112,17 @@ case(1) ## real pole/zero combination if(length(zer)) - num = [1 -zer(1)]; + num = [1, -zer(1)]; zer = zer(2:length(zer)); endif - den = [1 -pol(1)]; + den = [1, -pol(1)]; pol = pol(2:length(pol)); case(2) ## got a complex pole or zero, need two roots (if available) if(length(zer) > 1) [num,zer] = zp2ssg2(zer); # get two zeros elseif(length(zer) == 1) - num = [1 -zer]; # use last zero (better be real!) + num = [1, -zer]; # use last zero (better be real!) zer = []; endif [den,pol] = zp2ssg2(pol); # get two poles
--- a/scripts/finance/npv.m +++ b/scripts/finance/npv.m @@ -52,10 +52,9 @@ if is_scalar (r) d = 1 ./ (1 + r) .^ (0 : n); elseif (is_vector (r) && (length (r) == n)) - d = [1, 1 ./ cumprod (reshape (1 + r, 1, n))]; + d = [1, (1 ./ cumprod (reshape (1 + r, 1, n)))]; else - error (["npv: r has be a scalar ", ... - "or a vector of the same length as p"]); + error ("npv: r must be a scalar or a vector of the same length as p"); endif if (nargin == 3)
--- a/scripts/statistics/base/studentize.m +++ b/scripts/statistics/base/studentize.m @@ -39,7 +39,7 @@ elseif is_matrix (x) l = ones (rows (x), 1); t = x - l * mean (x); - t = t ./ (l * max ([std (t); !any (t)])); + t = t ./ (l * max ([(std (t)); (! any (t))])); else error ("studentize: x must be a vector or a matrix."); endif
--- a/scripts/statistics/base/values.m +++ b/scripts/statistics/base/values.m @@ -37,7 +37,7 @@ n = length (x); x = reshape (x, n, 1); s = sort (x); - v = s([1; find (s(2:n) > s(1:n-1)) + 1]); + v = s([1; (find (s(2:n) > s(1:n-1)) + 1)]); if (i) v = [v; NaN]; endif
--- a/scripts/statistics/distributions/exponential_cdf.m +++ b/scripts/statistics/distributions/exponential_cdf.m @@ -32,8 +32,7 @@ [retval, x, l] = common_size (x, l); if (retval > 0) - error (["exponential_cdf: ", - "x and lambda must be of common size or scalar"]); + error ("exponential_cdf: x and lambda must be of common size or scalar"); endif [r, c] = size (x);
--- a/scripts/statistics/distributions/poisson_cdf.m +++ b/scripts/statistics/distributions/poisson_cdf.m @@ -30,8 +30,7 @@ [retval, x, l] = common_size (x, l); if (retval > 0) - error (["poisson_cdf: ", - "x and lambda must be of common size or scalar"]); + error ("poisson_cdf: x and lambda must be of common size or scalar"); endif [r, c] = size (x);
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +1999-12-15 John W. Eaton <jwe@bevo.che.wisc.edu> + + * lex.l (Vwarn_separator_insert): New variable. + (syms_of_lex): DEFVAR it. + (warn_separator_insert): New function. + (maybe_warn_separator_insert): New function. + Use new stuff to allow warnings for code that might result in + auto-insertion of commas or semicolons, depending on the value of + whitespace_in_literal_matrix. + + * parse.y (Fsource): Record function file name here too. + 1999-12-13 John W. Eaton <jwe@bevo.che.wisc.edu> * variables.cc (link_to_global_variable): If the local symbol is
--- a/src/lex.l +++ b/src/lex.l @@ -163,6 +163,8 @@ static int Vwhitespace_in_literal_matrix; +static bool Vwarn_separator_insert = false; + // Forward declarations for functions defined at the bottom of this // file. @@ -186,6 +188,7 @@ static bool have_ellipsis_continuation (bool trailing_comments_ok = true); static yum_yum eat_whitespace (void); static yum_yum eat_continuation (void); +static void maybe_warn_separator_insert (char sep); %} @@ -277,13 +280,21 @@ <MATRIX>{S}*\,{S}* { current_input_column += yyleng; + int tmp = eat_continuation (); + lexer_flags.quote_is_transpose = false; lexer_flags.cant_be_identifier = false; lexer_flags.convert_spaces_to_comma = true; - if (Vwhitespace_in_literal_matrix != 2 - && (tmp & ATE_NEWLINE) == ATE_NEWLINE) - unput (';'); + + if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) + { + maybe_warn_separator_insert (';'); + + if (Vwhitespace_in_literal_matrix != 2) + unput (';'); + } + return (','); } @@ -296,21 +307,31 @@ <MATRIX>{S}+ { current_input_column += yyleng; - if (Vwhitespace_in_literal_matrix != 2) + + int tmp = eat_continuation (); + int bin_op = next_token_is_bin_op (true); + int postfix_un_op = next_token_is_postfix_unary_op (true); + + if (! (postfix_un_op || bin_op) + && nesting_level.is_bracket () + && lexer_flags.convert_spaces_to_comma) { - int tmp = eat_continuation (); - int bin_op = next_token_is_bin_op (true); - int postfix_un_op = next_token_is_postfix_unary_op (true); + if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) + { + maybe_warn_separator_insert (';'); - if (! (postfix_un_op || bin_op) - && nesting_level.is_bracket () - && lexer_flags.convert_spaces_to_comma) + if (Vwhitespace_in_literal_matrix != 2) + unput (';'); + } + + if (Vwhitespace_in_literal_matrix != 2) { lexer_flags.quote_is_transpose = false; lexer_flags.cant_be_identifier = false; lexer_flags.convert_spaces_to_comma = true; - if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) - unput (';'); + + maybe_warn_separator_insert (','); + return (','); } } @@ -341,6 +362,7 @@ <MATRIX>{S}*{NL}{SNLCMT}* { fixup_column_count (yytext); eat_whitespace (); + if (Vwhitespace_in_literal_matrix != 2) { lexer_flags.quote_is_transpose = false; @@ -349,8 +371,13 @@ if (nesting_level.none ()) return LEXICAL_ERROR; + } - if (nesting_level.is_bracket ()) + if (nesting_level.is_bracket ()) + { + maybe_warn_separator_insert (';'); + + if (Vwhitespace_in_literal_matrix != 2) return ';'; } } @@ -1850,7 +1877,7 @@ int c1 = yyinput (); unput (c1); - if (lexer_flags.bracketflag && Vwhitespace_in_literal_matrix != 2) + if (lexer_flags.bracketflag) { int bin_op = next_token_is_bin_op (spc_gobbled); @@ -1862,8 +1889,13 @@ && nesting_level.is_bracket () && lexer_flags.convert_spaces_to_comma) { - unput (','); - return ']'; + maybe_warn_separator_insert (','); + + if (Vwhitespace_in_literal_matrix != 2) + { + unput (','); + return ']'; + } } } } @@ -1878,7 +1910,7 @@ static void maybe_unput_comma (int spc_gobbled) { - if (Vwhitespace_in_literal_matrix != 2 && nesting_level.is_bracket ()) + if (nesting_level.is_bracket ()) { int bin_op = next_token_is_bin_op (spc_gobbled); @@ -1895,12 +1927,31 @@ int dot_op = (c1 == '.' && (isalpha (c2) || isspace (c2) || c2 == '_')); - int index_op = (c1 == '(' - && (Vwhitespace_in_literal_matrix == 0 - || ! spc_gobbled)); + if (postfix_un_op || bin_op || sep_op || dot_op) + return; + + int index_op = (c1 == '('); + + if (index_op) + { + // If there is no space before the '(', we don't insert a comma. + if (! spc_gobbled) + return; + + maybe_warn_separator_insert (','); - if (! (postfix_un_op || bin_op || sep_op || dot_op || index_op)) - unput (','); + // If there is a space, we only insert a comma if we are + // trying to be Matlab-like. + if (Vwhitespace_in_literal_matrix == 1) + unput (','); + } + else + { + maybe_warn_separator_insert (','); + + if (Vwhitespace_in_literal_matrix != 2) + unput (','); + } } } @@ -2150,6 +2201,30 @@ quote_is_transpose = false; } +static void +maybe_warn_separator_insert (char sep) +{ + string nm = curr_fcn_file_full_name; + + if (Vwarn_separator_insert) + { + if (nm.empty ()) + warning ("potential auto-insertion of `%c' near line %d", + sep, input_line_number); + else + warning ("potential auto-insertion of `%c' near line %d of file %s", + sep, input_line_number, nm.c_str ()); + } +} + +static int +warn_separator_insert (void) +{ + Vwarn_separator_insert = check_preference ("warn_separator_insert"); + + return 0; +} + static int whitespace_in_literal_matrix (void) { @@ -2173,6 +2248,10 @@ void symbols_of_lex (void) { + DEFVAR (warn_separator_insert, 0.0, warn_separator_insert, + "print warning if commas or semicolons that might be inserted\n\ +automatically in literal matrices"); + DEFVAR (whitespace_in_literal_matrix, "", whitespace_in_literal_matrix, "control auto-insertion of commas and semicolons in literal matrices"); }
--- a/src/parse.y +++ b/src/parse.y @@ -3085,16 +3085,27 @@ if (nargin == 1) { - string file = args(0).string_value (); + string file_name = args(0).string_value (); if (! error_state) { - file = file_ops::tilde_expand (file); - - parse_fcn_file (file, true, true); + string file_full_name = file_ops::tilde_expand (file_name); + + unwind_protect::begin_frame ("Fsource"); + + unwind_protect_str (curr_fcn_file_name); + unwind_protect_str (curr_fcn_file_full_name); + + curr_fcn_file_name = file_name; + curr_fcn_file_full_name = file_full_name; + + parse_fcn_file (file_full_name, true, true); if (error_state) - error ("source: error sourcing file `%s'", file.c_str ()); + error ("source: error sourcing file `%s'", + file_full_name.c_str ()); + + unwind_protect::run_frame ("Fsource"); } else error ("source: expecting file name as argument");