Mercurial > hg > octave-nkf
changeset 496:e7c5b23b34d3
[project @ 1994-07-06 15:02:26 by jwe]
author | jwe |
---|---|
date | Wed, 06 Jul 1994 15:02:26 +0000 |
parents | 36e25526fa9f |
children | 88614b380d6e |
files | src/parse.y |
diffstat | 1 files changed, 54 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- 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 <tree_type> input command -%type <tree_type> ans_expression expression simple_expr simple_expr1 -%type <tree_type> title +%type <tree_expression_type> expression simple_expr simple_expr1 +%type <tree_expression_type> ans_expression title %type <tree_matrix_type> matrix %type <tree_identifier_type> identifier %type <tree_function_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 ()