Mercurial > hg > octave-terminal
changeset 2525:8561d88be5f2
[project @ 1996-11-17 21:23:31 by jwe]
author | jwe |
---|---|
date | Sun, 17 Nov 1996 21:23:31 +0000 |
parents | 7dc71ca5d092 |
children | aad9cc70dfb2 |
files | src/ChangeLog src/parse.y |
diffstat | 2 files changed, 91 insertions(+), 87 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ Sun Nov 17 14:14:48 1996 John W. Eaton <jwe@bevo.che.wisc.edu> + * parse.y (set_stmt_print_flag): New function. + (sep_type): New member for bison %union declaration. + Simplify rules for statement lists keeping track of the type of + the first separator in the values associated with the + nonterminals for the separators. + * lex.l (handle_identifier): Set lexer_flags.doing_set if the token is "gset", not "set".
--- a/src/parse.y +++ b/src/parse.y @@ -228,6 +228,9 @@ // Maybe print a warning. Duh. static void maybe_warn_missing_semi (tree_statement_list *); +// Set the print flag for a statement based on the separator type. +static void set_stmt_print_flag (tree_statement_list *, char, bool); + #define ABORT_PARSE \ do \ { \ @@ -250,6 +253,7 @@ token *tok_val; // Types for the nonterminals we generate. + char sep_type; tree *tree_type; tree_matrix *tree_matrix_type; tree_matrix_row *tree_matrix_row_type; @@ -310,6 +314,7 @@ %token USING TITLE WITH COLON OPEN_BRACE CLOSE_BRACE CLEAR // Nonterminals we construct. +%type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep %type <tree_type> input %type <tree_matrix_type> rows rows1 %type <tree_matrix_row_type> matrix_row matrix_row1 @@ -398,60 +403,21 @@ | error ; -simple_list : semi_comma - { $$ = 0; } - | comma_semi - { $$ = 0; } - | simple_list1 - { $$ = $1; } - | simple_list1 comma_semi - { $$ = $1; } - | simple_list1 semi_comma +simple_list : simple_list1 opt_sep_no_nl { - tree_statement *tmp = $1->rear (); - tmp->set_print_flag (0); + set_stmt_print_flag ($1, $2, false); $$ = $1; } ; simple_list1 : statement { $$ = new tree_statement_list ($1); } - | semi_comma statement - { $$ = new tree_statement_list ($2); } - | comma_semi statement - { $$ = new tree_statement_list ($2); } - | simple_list1 semi_comma statement + | simple_list1 sep_no_nl statement { - tree_statement *tmp = $1->rear (); - tmp->set_print_flag (0); + set_stmt_print_flag ($1, $2, false); $1->append ($3); $$ = $1; } - | simple_list1 comma_semi statement - { - $1->append ($3); - maybe_warn_missing_semi ($1); - $$ = $1; - } - ; - -semi_comma : ';' - | semi_comma ',' - | semi_comma ';' - ; - -comma_semi : ',' - | comma_semi ';' - | comma_semi ',' - ; - -comma_nl_sep : ',' - | '\n' - | comma_nl_sep sep - ; - -semi_sep : ';' - | semi_sep sep ; opt_list : // empty @@ -460,20 +426,9 @@ { $$ = $1; } ; -list : list1 - { - maybe_warn_missing_semi ($1); - $$ = $1; - } - | list1 comma_nl_sep +list : list1 opt_sep { - maybe_warn_missing_semi ($1); - $$ = $1; - } - | list1 semi_sep - { - tree_statement *tmp = $1->rear (); - tmp->set_print_flag (0); + set_stmt_print_flag ($1, $2, true); $$ = $1; } ; @@ -483,16 +438,9 @@ lexer_flags.beginning_of_function = 0; $$ = new tree_statement_list ($1); } - | list1 comma_nl_sep statement + | list1 sep statement { - maybe_warn_missing_semi ($1); - $1->append ($3); - $$ = $1; - } - | list1 semi_sep statement - { - tree_statement *tmp = $1->rear (); - tmp->set_print_flag (0); + set_stmt_print_flag ($1, $2, true); $1->append ($3); $$ = $1; } @@ -677,28 +625,28 @@ lexer_flags.iffing--; $$ = $1; } - | UNWIND optsep opt_list CLEANUP optsep opt_list END + | UNWIND opt_sep opt_list CLEANUP opt_sep opt_list END { if (! ($$ = make_unwind_command ($1, $3, $6, $7))) ABORT_PARSE; } - | TRY optsep opt_list CATCH optsep opt_list END + | TRY opt_sep opt_list CATCH opt_sep opt_list END { if (! ($$ = make_try_command ($1, $3, $6, $7))) ABORT_PARSE; } - | WHILE expression optsep opt_list END + | WHILE expression opt_sep opt_list END { if (! ($$ = make_while_command ($1, $2, $4, $5))) ABORT_PARSE; } - | FOR variable '=' expression optsep opt_list END + | FOR variable '=' expression opt_sep opt_list END { if (! ($$ = make_for_command ($1, $2, $4, $6, $7))) ABORT_PARSE; } | FOR '[' screwed_again matrix_row SCREW_TWO '=' - expression optsep opt_list END + expression opt_sep opt_list END { if (! ($$ = make_for_command ($1, $4, $7, $9, $10))) ABORT_PARSE; @@ -736,7 +684,7 @@ } ; -if_cmd_list1 : expression optsep opt_list +if_cmd_list1 : expression opt_sep opt_list { $$ = start_if_command ($1, $3); } | if_cmd_list1 elseif_clause { @@ -745,26 +693,14 @@ } ; -elseif_clause : ELSEIF optsep expression optsep opt_list +elseif_clause : ELSEIF opt_sep expression opt_sep opt_list { $$ = make_elseif_clause ($3, $5); } ; -else_clause : ELSE optsep opt_list +else_clause : ELSE opt_sep opt_list { $$ = new tree_if_clause ($3); } ; -optsep : // empty - | sep - ; - -sep : ',' - | ';' - | '\n' - | sep ',' - | sep ';' - | sep '\n' - ; - screwed_again : // empty { lexer_flags.maybe_screwed_again++; } ; @@ -995,9 +931,9 @@ } ; -func_def3 : param_list optsep opt_list fcn_end_or_eof +func_def3 : param_list opt_sep opt_list fcn_end_or_eof { $$ = start_function_def ($1, $3); } - | optsep opt_list fcn_end_or_eof + | opt_sep opt_list fcn_end_or_eof { $$ = start_function_def (0, $2); } ; @@ -1171,6 +1107,42 @@ } ; +sep_no_nl : ',' + { $$ = ','; } + | ';' + { $$ = ';'; } + | sep_no_nl ',' + { $$ = $1; } + | sep_no_nl ';' + { $$ = $1; } + ; + +opt_sep_no_nl : // empty + { $$ = 0; } + | sep_no_nl + { $$ = $1; } + ; + +sep : ',' + { $$ = ','; } + | ';' + { $$ = ';'; } + | '\n' + { $$ = '\n'; } + | sep ',' + { $$ = $1; } + | sep ';' + { $$ = $1; } + | sep '\n' + { $$ = $1; } + ; + +opt_sep : // empty + { $$ = 0; } + | sep + { $$ = $1; } + ; + %% // Generic error messages. @@ -2137,6 +2109,32 @@ } } +static void +set_stmt_print_flag (tree_statement_list *list, char sep, + bool warn_missing_semi) +{ + switch (sep) + { + case ';': + { + tree_statement *tmp = list->rear (); + tmp->set_print_flag (0); + } + break; + + case 0: + case ',': + case '\n': + if (warn_missing_semi) + maybe_warn_missing_semi (list); + break; + + default: + warning ("unrecognized separator type!"); + break; + } +} + static int warn_assign_as_truth_value (void) {