# HG changeset patch # User jwe # Date 789099103 0 # Node ID 46a2983cb2972ae8af547d5c0efbb254f7241758 # Parent df3c4da3adb05bc03a90b560d509c9314fdfe762 [project @ 1995-01-03 02:08:32 by jwe] diff -r df3c4da3adb0 -r 46a2983cb297 src/error.cc --- a/src/error.cc Mon Jan 02 20:59:39 1995 +0000 +++ b/src/error.cc Tue Jan 03 02:11:43 1995 +0000 @@ -65,6 +65,31 @@ delete [] msg; } +static void +error_1 (const char *name, const char *fmt, va_list args) +{ + if (error_state != -2) + { + if (! error_state) + error_state = 1; + + if (! suppress_octave_error_messages) + { + int len = 0; + if (fmt && *fmt && fmt[(len = strlen (fmt)) - 1] == '\n') + { + error_state = -2; + char *tmp_fmt = strsave (fmt); + tmp_fmt[len - 1] = '\0'; + verror (name, tmp_fmt, args); + delete [] tmp_fmt; + } + else + verror (name, fmt, args); + } + } +} + void message (const char *name, const char *fmt, ...) { @@ -96,30 +121,18 @@ void error (const char *fmt, ...) { - if (error_state == -2) - return; - - if (! error_state) - error_state = 1; - - if (suppress_octave_error_messages) - return; - va_list args; va_start (args, fmt); + error_1 ("error", fmt, args); + va_end (args); +} - int len = 0; - if (fmt && *fmt && fmt[(len = strlen (fmt)) - 1] == '\n') - { - error_state = -2; - char *tmp_fmt = strsave (fmt); - tmp_fmt[len - 1] = '\0'; - verror ("error", tmp_fmt, args); - delete [] tmp_fmt; - } - else - verror ("error", fmt, args); - +void +parse_error (const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + error_1 (0, fmt, args); va_end (args); } diff -r df3c4da3adb0 -r 46a2983cb297 src/error.h --- a/src/error.h Mon Jan 02 20:59:39 1995 +0000 +++ b/src/error.h Tue Jan 03 02:11:43 1995 +0000 @@ -39,6 +39,7 @@ extern void usage (const char *fmt, ...); extern void warning (const char *fmt, ...); extern void error (const char *fmt, ...); +extern void parse_error (const char *fmt, ...); extern void panic (const char *fmt, ...); // Current error state. diff -r df3c4da3adb0 -r 46a2983cb297 src/octave.cc --- a/src/octave.cc Mon Jan 02 20:59:39 1995 +0000 +++ b/src/octave.cc Tue Jan 03 02:11:43 1995 +0000 @@ -271,7 +271,9 @@ do { reset_parser (); + retval = yyparse (); + if (retval == 0 && global_command) { global_command->eval (print); @@ -636,6 +638,9 @@ } while (retval == 0); + if (retval == 1 && ! error_state) + retval = 0; + clean_up_and_exit (retval); } diff -r df3c4da3adb0 -r 46a2983cb297 src/parse.y --- a/src/parse.y Mon Jan 02 20:59:39 1995 +0000 +++ b/src/parse.y Tue Jan 03 02:11:43 1995 +0000 @@ -161,7 +161,6 @@ do \ { \ global_command = 0; \ - reset_parser (); \ yyerrok; \ if (interactive) \ YYACCEPT; \ @@ -632,8 +631,7 @@ { if (!looping) { - yyerror ("parse error"); - error ("break: only meaningful within a `for'\ + yyerror ("break: only meaningful within a `for'\ or `while' loop"); ABORT_PARSE; } @@ -643,8 +641,7 @@ { if (!looping) { - yyerror ("parse error"); - error ("continue: only meaningful within a\ + yyerror ("continue: only meaningful within a\ `for' or `while' loop"); ABORT_PARSE; } @@ -655,8 +652,7 @@ { if (!defining_func) { - yyerror ("parse error"); - error ("return: only meaningful within a function"); + yyerror ("return: only meaningful within a function"); ABORT_PARSE; } $$ = new tree_return_command ($1->line (), $1->column ()); @@ -719,8 +715,7 @@ ($1, $3, 0, 0, $2->line (), $2->column ()); } | NUM '=' expression { - yyerror ("parse error"); - error ("invalid assignment to a number"); + yyerror ("invalid assignment to a number"); $$ = 0; ABORT_PARSE; } @@ -844,10 +839,7 @@ { $$ = $1->chain ($3); if (! $$) - { - yyerror ("parse error"); - ABORT_PARSE; - } + ABORT_PARSE; } ; @@ -941,8 +933,7 @@ { $$ = new tree_parameter_list ($2); } | return_list_x error { - yyerror ("parse error"); - error ("invalid function return list"); + yyerror ("invalid function return list"); ABORT_PARSE; } | return_list1 ',' identifier @@ -954,8 +945,7 @@ char *id_name = $1->name (); // if (is_text_function_name (id_name)) // { -// yyerror ("parse error"); -// error ("invalid use of reserved word %s", id_name); +// yyerror ("invalid use of reserved word %s", id_name); // ABORT_PARSE; // } @@ -1051,8 +1041,7 @@ { $$ = make_index_expression ($1, $3); } | indirect_ref '[' { - yyerror ("parse error"); - error ("use `(\' and `)\' as index operators, not\ + yyerror ("use `(\' and `)\' as index operators, not\ `[\' and `]\'"); $$ = 0; ABORT_PARSE; @@ -1090,14 +1079,12 @@ { $1->append ($3); } | '(' error { - yyerror ("parse error"); - error ("invalid parameter list"); + yyerror ("invalid parameter list"); ABORT_PARSE; } | param_list1 ',' error { - yyerror ("parse error"); - error ("invalid parameter list"); + yyerror ("invalid parameter list"); ABORT_PARSE; } ; @@ -1195,16 +1182,18 @@ if (err_col == 0 && line) err_col = strlen (line) + 1; -// Print a message like `parse error', maybe printing the line number -// and file name. - ostrstream output_buf; - output_buf.form ("\n%s", s); + if (reading_fcn_file || reading_script_file) + output_buf << "parse error near line " << input_line_number + << " of file " << curr_fcn_file_name << ".m:"; + else + output_buf << "parse error:"; - if (reading_fcn_file || reading_script_file) - output_buf.form (" near line %d of file %s.m", input_line_number, - curr_fcn_file_name); + if (s && strcmp (s, "parse error") != 0) + output_buf << "\n\n " << s; + + output_buf << "\n\n"; if (line) { @@ -1214,16 +1203,25 @@ len--; line[len] = '\0'; } + // Print the line, maybe with a pointer near the error token. - if (err_col > len) - output_buf.form (":\n\n %s\n\n", line); - else - output_buf.form (":\n\n %s\n %*s\n\n", line, err_col, "^"); + + output_buf << " " << line << "\n"; + if (err_col <= len) + { + for (int i = 0; i < err_col + 1; i++) + output_buf << " "; + output_buf << "^"; + } } - else - output_buf << "\n\n"; + + output_buf << "\n" << ends; - maybe_page_output (output_buf); + char *msg = output_buf.str (); + + parse_error (msg); + + delete [] msg; } // Error mesages for mismatched end tokens. @@ -1584,20 +1582,13 @@ retval = new tree_multi_assignment_expression (id_list, t, l, c); } else - { - yyerror ("parse error"); - error ("RHS must be an expression that can return\ - multiple values"); - } + yyerror ("RHS must be an expression that returns multiple values"); } else panic_impossible (); } else - { - yyerror ("parse error"); - error ("invalid identifier list for assignment"); - } + yyerror ("invalid identifier list for assignment"); return retval; }