# HG changeset patch # User jwe # Date 812717419 0 # Node ID 74f9e88a2c12aa0f456db67b3ee76580081bc795 # Parent fe9c39fd89c7420ec7bab93bf7af6e5f54be52d0 [project @ 1995-10-03 10:49:31 by jwe] diff --git a/src/parse.y b/src/parse.y --- a/src/parse.y +++ b/src/parse.y @@ -157,6 +157,9 @@ static tree_index_expression *make_index_expression (tree_indirect_ref *indir, tree_argument_list *args); +// Maybe print a warning. Duh. +static void maybe_warn_missing_semi (tree_statement_list *); + #define ABORT_PARSE \ do \ { \ @@ -329,14 +332,21 @@ | comma_semi { $$ = 0; } | simple_list1 - { $$ = $1; } + { + maybe_warn_missing_semi ($1); + $$ = $1; + } + | simple_list1 comma_semi + { + maybe_warn_missing_semi ($1); + $$ = $1; + } | simple_list1 semi_comma { tree_statement *tmp = $1->rear (); tmp->set_print_flag (0); + $$ = $1; } - | simple_list1 comma_semi - { $$ = $1; } ; simple_list1 : statement @@ -350,9 +360,14 @@ tree_statement *tmp = $1->rear (); tmp->set_print_flag (0); $1->append ($3); + $$ = $1; } | simple_list1 comma_semi statement - { $1->append ($3); } + { + $1->append ($3); + maybe_warn_missing_semi ($1); + $$ = $1; + } ; semi_comma : ';' @@ -381,9 +396,14 @@ ; list : list1 - { $$ = $1; } + { + maybe_warn_missing_semi ($1); + $$ = $1; + } | list1 comma_nl_sep - { $$ = $1; } + { + $$ = $1; + } | list1 semi_sep { tree_statement *tmp = $1->rear (); @@ -397,12 +417,17 @@ $$ = new tree_statement_list ($1); } | list1 comma_nl_sep statement - { $1->append ($3); } + { + $1->append ($3); + maybe_warn_missing_semi ($1); + $$ = $1; + } | list1 semi_sep statement { tree_statement *tmp = $1->rear (); tmp->set_print_flag (0); $1->append ($3); + $$ = $1; } ; @@ -1661,3 +1686,16 @@ return retval; } + +static void +maybe_warn_missing_semi (tree_statement_list *t) +{ + if (defining_func && user_pref.warn_missing_semicolon) + { + tree_statement *tmp = t->rear(); + if (tmp->is_expression ()) + + warning ("missing semicolon near line %d, column %d", + tmp->line (), tmp->column ()); + } +} diff --git a/src/user-prefs.cc b/src/user-prefs.cc --- a/src/user-prefs.cc +++ b/src/user-prefs.cc @@ -515,10 +515,9 @@ } -// Generate warning if a statement in a function or script file is not -// terminated with a semicolon. Useful for checking scripts and -// functions that should only produce output using explicit printing -// statements. +// Generate warning if a statement in a function is not terminated +// with a semicolon. Useful for checking functions that should only +// produce output using explicit printing statements. int warn_missing_semicolon (void) diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -1829,8 +1829,8 @@ DEFVAR ("warn_missing_semicolon", SBV_warn_missing_semicolon, 0.0, 0, warn_missing_semicolon, - "produce a warning if a statement in a script or function file is -not terminated with a semicolon"); + "produce a warning if a statement in a function file is not +terminated with a semicolon"); DEFVAR ("whitespace_in_literal_matrix", SBV_whitespace_in_literal_matrix, "", 0,