# HG changeset patch # User jwe # Date 773506946 0 # Node ID e7c5b23b34d3fca8e793cf3624d62165c3537e3c # Parent 36e25526fa9f6ac261e043fefa2cedf6647b5b5a [project @ 1994-07-06 15:02:26 by jwe] diff --git a/src/parse.y b/src/parse.y --- a/src/parse.y +++ b/src/parse.y @@ -106,17 +106,25 @@ // Nonzero means we're looking at the style part of a plot command. int in_plot_style = 0; -// Check to see that end statements are properly matched. -static int check_end (token *tok, token::end_tok_type expected); +// Forward declarations for some functions defined at the bottom of +// the file. + +// Generic error messages. +static void yyerror (char *s); // Error mesages for mismatched end statements. static void end_error (char *type, token::end_tok_type ettype, int l, int c); -// Generic error messages. -static void yyerror (char *s); +// Check to see that end statements are properly matched. +static int check_end (token *tok, token::end_tok_type expected); -static tree *maybe_convert_to_ans_assign (tree *expr); -static void maybe_warn_assign_as_truth_value (tree *expr); +// Try to figure out early if an expression should become an +// assignment to the builtin variable ans. +static tree_expression *maybe_convert_to_ans_assign (tree_expression *expr); + +// Maybe print a warning if an assignment expression is used as the +// test in a logical expression. +static void maybe_warn_assign_as_truth_value (tree_expression *expr); #define ABORT_PARSE \ do \ @@ -143,6 +151,7 @@ // Types for the nonterminals we generate. tree *tree_type; + tree_expression *tree_expression_type; tree_constant *tree_constant_type; tree_matrix *tree_matrix_type; tree_identifier *tree_identifier_type; @@ -186,8 +195,8 @@ // Nonterminals we construct. %type input command -%type ans_expression expression simple_expr simple_expr1 -%type title +%type expression simple_expr simple_expr1 +%type ans_expression title %type matrix %type identifier %type func_def func_def1 func_def2 func_def3 @@ -327,6 +336,7 @@ { $$ = new tree_command_list (); } | list { $$ = $1; } + ; list : list1 { $$ = $1->reverse (); } @@ -475,13 +485,13 @@ using : using1 { + in_plot_using = 0; $$ = $1; - in_plot_using = 0; } | using1 expression { + in_plot_using = 0; $$ = $1->set_format ($2); - in_plot_using = 0; } ; @@ -796,14 +806,14 @@ { $$ = new tree_constant (Complex (0.0, $1->number ())); } | TEXT { $$ = new tree_constant ($1->string ()); } - | word_list_cmd - { $$ = $1; } | '(' expression ')' { if ($2->is_assignment_expression ()) ((tree_assignment_expression *) $2) -> in_parens++; $$ = $2; } + | word_list_cmd + { $$ = $1; } | variable { $$ = $1; } | matrix @@ -1179,6 +1189,34 @@ fprintf (stderr, "\n\n"); } +static void +end_error (char *type, token::end_tok_type ettype, int l, int c) +{ + static char *fmt = "%s command matched by `%s' near line %d column %d"; + + switch (ettype) + { + case token::simple_end: + error (fmt, type, "end", l, c); + break; + case token::for_end: + error (fmt, type, "endfor", l, c); + break; + case token::function_end: + error (fmt, type, "endfunction", l, c); + break; + case token::if_end: + error (fmt, type, "endif", l, c); + break; + case token::while_end: + error (fmt, type, "endwhile", l, c); + break; + default: + panic_impossible (); + break; + } +} + static int check_end (token *tok, token::end_tok_type expected) { @@ -1214,34 +1252,6 @@ return 0; } -static void -end_error (char *type, token::end_tok_type ettype, int l, int c) -{ - static char *fmt = "%s command matched by `%s' near line %d column %d"; - - switch (ettype) - { - case token::simple_end: - error (fmt, type, "end", l, c); - break; - case token::for_end: - error (fmt, type, "endfor", l, c); - break; - case token::function_end: - error (fmt, type, "endfunction", l, c); - break; - case token::if_end: - error (fmt, type, "endif", l, c); - break; - case token::while_end: - error (fmt, type, "endwhile", l, c); - break; - default: - panic_impossible (); - break; - } -} - /* * Need to make sure that the expression isn't already an identifier * that has a name, or an assignment expression. @@ -1255,8 +1265,8 @@ * * XXX FIXME XXX -- we should probably delay doing this until eval-time. */ -tree * -maybe_convert_to_ans_assign (tree *expr) +static tree_expression * +maybe_convert_to_ans_assign (tree_expression *expr) { if (expr->is_index_expression ()) { @@ -1280,8 +1290,8 @@ } } -void -maybe_warn_assign_as_truth_value (tree *expr) +static void +maybe_warn_assign_as_truth_value (tree_expression *expr) { if (user_pref.warn_assign_as_truth_value && expr->is_assignment_expression ()