# HG changeset patch # User jwe # Date 859791980 0 # Node ID 5448c8cba4023000cea98762d165c024db394998 # Parent 8c516da3c1f75aeef57e09413d5d6083266fab3d [project @ 1997-03-31 07:06:10 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -2,6 +2,8 @@ * symtab.h, symtab.cc: Use bool instead of int in more places. * variables.h, variables.cc: Likewise. + * lex.h, lex.l: Likewise. + * parse.y: Likewise. * help.cc, input.cc, lex.l, load-save.cc, parse.y, pt-fcn.cc: Change callers of symbol_table::lookup to use bool instead of int, and to make use of default arguments. diff --git a/src/lex.h b/src/lex.h --- a/src/lex.h +++ b/src/lex.h @@ -28,7 +28,7 @@ #ifdef YY_INPUT #undef YY_INPUT #endif -#define YY_INPUT(buf,result,max_size) \ +#define YY_INPUT(buf, result, max_size) \ if ((result = octave_read (buf, max_size)) < 0) \ YY_FATAL_ERROR ("octave_read () in flex scanner failed"); @@ -49,14 +49,14 @@ do \ { \ current_input_column += yyleng; \ - lexer_flags.quote_is_transpose = 0; \ - lexer_flags.cant_be_identifier = 0; \ - lexer_flags.convert_spaces_to_comma = 1; \ + lexer_flags.quote_is_transpose = false; \ + lexer_flags.cant_be_identifier = false; \ + lexer_flags.convert_spaces_to_comma = true; \ return (tok); \ } \ while (0) -#define TOK_PUSH_AND_RETURN(name,tok) \ +#define TOK_PUSH_AND_RETURN(name, tok) \ do \ { \ yylval.tok_val = new token (name, input_line_number, \ @@ -66,14 +66,14 @@ } \ while (0) -#define BIN_OP_RETURN(tok,convert) \ +#define BIN_OP_RETURN(tok, convert) \ do \ { \ yylval.tok_val = new token (input_line_number, current_input_column); \ token_stack.push (yylval.tok_val); \ current_input_column += yyleng; \ - lexer_flags.quote_is_transpose = 0; \ - lexer_flags.cant_be_identifier = 0; \ + lexer_flags.quote_is_transpose = false; \ + lexer_flags.cant_be_identifier = true; \ lexer_flags.convert_spaces_to_comma = convert; \ return (tok); \ } \ @@ -119,55 +119,55 @@ void init (void); - // Nonzero means we think we are looking at the beginning of a - // function definition. - int beginning_of_function; - // Brace level count. int braceflag; - // Another context hack, this time for the plot command's `using', - // `title', and `with' keywords. - int cant_be_identifier; - - // Nonzero means that we should convert spaces to a comma inside a - // matrix definition. - int convert_spaces_to_comma; - - // Nonzero means we're in the middle of defining a function. - int defining_func; - - // Nonzero means we're parsing the return list for a function. - int looking_at_return_list; - - // Nonzero means we're parsing the parameter list for a function. - int looking_at_parameter_list; - - // GAG. Stupid kludge so that [[1,2][3,4]] will work. - int do_comma_insert; - - // Nonzero means we think we are looking at a set command. - int doing_set; - - // Nonzero means we're looking at the range part of a plot command. - int in_plot_range; - - // Nonzero means we're looking at the using part of a plot command. - int in_plot_using; - - // Nonzero means we're looking at the style part of a plot command. - int in_plot_style; - - // Nonzero means we're looking at an indirect reference to a - // structure element. - int looking_at_indirect_ref; - // Nonzero means we're in the middle of defining a loop. int looping; + // Nonzero means we think we are looking at the beginning of a + // function definition. + bool beginning_of_function; + + // Another context hack, this time for the plot command's `using', + // `title', and `with' keywords. + bool cant_be_identifier; + + // Nonzero means that we should convert spaces to a comma inside a + // matrix definition. + bool convert_spaces_to_comma; + + // Nonzero means we're in the middle of defining a function. + bool defining_func; + + // Nonzero means we're parsing the return list for a function. + bool looking_at_return_list; + + // Nonzero means we're parsing the parameter list for a function. + bool looking_at_parameter_list; + + // GAG. Stupid kludge so that [[1,2][3,4]] will work. + bool do_comma_insert; + + // Nonzero means we think we are looking at a set command. + bool doing_set; + + // Nonzero means we're looking at the range part of a plot command. + bool in_plot_range; + + // Nonzero means we're looking at the using part of a plot command. + bool in_plot_using; + + // Nonzero means we're looking at the style part of a plot command. + bool in_plot_style; + + // Nonzero means we're looking at an indirect reference to a + // structure element. + bool looking_at_indirect_ref; + // Nonzero means we need to do some extra lookahead to avoid being // screwed by bogus function syntax. - int maybe_screwed; + bool maybe_screwed; // Nonzero means we need to do some extra lookahead to avoid being // screwed by bogus function syntax. @@ -175,13 +175,13 @@ // Nonzero means we've seen something that means we must be past the // range part of a plot command. - int past_plot_range; + bool past_plot_range; // Nonzero means we're working on a plot command. - int plotting; + bool plotting; // Return transpose or start a string? - int quote_is_transpose; + bool quote_is_transpose; private: diff --git a/src/lex.l b/src/lex.l --- a/src/lex.l +++ b/src/lex.l @@ -174,16 +174,16 @@ static string plot_style_token (const string& s); static symbol_record *lookup_identifier (const string& s); static void grab_help_text (void); -static int match_any (char c, const char *s); -static int next_token_is_bin_op (int spc_prev, char *yytext); -static int next_token_is_postfix_unary_op (int spc_prev, char *yytext); +static bool match_any (char c, const char *s); +static bool next_token_is_bin_op (int spc_prev, char *yytext); +static bool next_token_is_postfix_unary_op (int spc_prev, char *yytext); static string strip_trailing_whitespace (char *s); static void handle_number (char *yytext); static int handle_string (char delim, int text_style = 0); static int handle_close_brace (int spc_gobbled); static int handle_identifier (const string& tok, int spc_gobbled); -static int have_continuation (int trailing_comments_ok = 1); -static int have_ellipsis_continuation (int trailing_comments_ok = 1); +static bool have_continuation (int trailing_comments_ok = 1); +static bool have_ellipsis_continuation (int trailing_comments_ok = 1); static yum_yum eat_whitespace (void); static yum_yum eat_continuation (void); @@ -218,9 +218,9 @@ {NL} { BEGIN 0; current_input_column = 1; - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; return '\n'; } @@ -278,9 +278,9 @@ {S}*\,{S}* { current_input_column += yyleng; int tmp = eat_continuation (); - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; if (Vwhitespace_in_literal_matrix != 2 && (tmp & ATE_NEWLINE) == ATE_NEWLINE) unput (';'); @@ -306,9 +306,9 @@ && nesting_level.is_brace () && lexer_flags.convert_spaces_to_comma) { - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) unput (';'); return (','); @@ -325,9 +325,9 @@ {SNLCMT}*;{SNLCMT}* { fixup_column_count (yytext); eat_whitespace (); - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; return ';'; } @@ -342,9 +342,9 @@ eat_whitespace (); if (Vwhitespace_in_literal_matrix != 2) { - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; if (nesting_level.none ()) return LEXICAL_ERROR; @@ -364,16 +364,16 @@ nesting_level.brace (); current_input_column += yyleng; - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; promptflag--; eat_whitespace (); if (lexer_flags.plotting && ! lexer_flags.past_plot_range) { - lexer_flags.in_plot_range = 1; + lexer_flags.in_plot_range = true; return OPEN_BRACE; } else @@ -389,7 +389,7 @@ if (lexer_flags.plotting && ! lexer_flags.past_plot_range) { - lexer_flags.in_plot_range = 0; + lexer_flags.in_plot_range = false; TOK_RETURN (CLOSE_BRACE); } else @@ -473,9 +473,9 @@ {NL} { current_input_column = 1; - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; if (nesting_level.none ()) return '\n'; @@ -491,7 +491,7 @@ "'" { current_input_column++; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.convert_spaces_to_comma = true; if (lexer_flags.quote_is_transpose) { @@ -519,9 +519,9 @@ ":" { if (lexer_flags.plotting && (lexer_flags.in_plot_range || lexer_flags.in_plot_using)) - BIN_OP_RETURN (COLON, 1); + BIN_OP_RETURN (COLON, true); else - BIN_OP_RETURN (':', 0); + BIN_OP_RETURN (':', false); } %{ @@ -535,7 +535,7 @@ && nesting_level.none ()) { grab_help_text (); - lexer_flags.beginning_of_function = 0; + lexer_flags.beginning_of_function = false; } else { @@ -545,9 +545,9 @@ } current_input_column = 1; - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; if (nesting_level.none ()) return '\n'; @@ -559,54 +559,54 @@ // Other operators. %} -".+" { BIN_OP_RETURN (EPLUS, 0); } -".-" { BIN_OP_RETURN (EMINUS, 0); } -".*" { BIN_OP_RETURN (EMUL, 0); } -"./" { BIN_OP_RETURN (EDIV, 0); } -".\\" { BIN_OP_RETURN (ELEFTDIV, 0); } -{EPOW} { BIN_OP_RETURN (EPOW, 0); } -".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, 1); } -"++" { do_comma_insert_check (); BIN_OP_RETURN (PLUS_PLUS, 1); } -"--" { do_comma_insert_check (); BIN_OP_RETURN (MINUS_MINUS, 1); } -"<=" { BIN_OP_RETURN (EXPR_LE, 0); } -"==" { BIN_OP_RETURN (EXPR_EQ, 0); } -{NOTEQ} { BIN_OP_RETURN (EXPR_NE, 0); } -">=" { BIN_OP_RETURN (EXPR_GE, 0); } -"|" { BIN_OP_RETURN (EXPR_OR, 0); } -"&" { BIN_OP_RETURN (EXPR_AND, 0); } -"<" { BIN_OP_RETURN (EXPR_LT, 0); } -">" { BIN_OP_RETURN (EXPR_GT, 0); } -"*" { BIN_OP_RETURN ('*', 0); } -"/" { BIN_OP_RETURN ('/', 0); } -"\\" { BIN_OP_RETURN (LEFTDIV, 0); } -";" { BIN_OP_RETURN (';', 1); } -"," { BIN_OP_RETURN (',', 1); } -{POW} { BIN_OP_RETURN (POW, 0); } -"=" { BIN_OP_RETURN ('=', 1); } -"||" { BIN_OP_RETURN (EXPR_OR_OR, 0); } -"&&" { BIN_OP_RETURN (EXPR_AND_AND, 0); } +".+" { BIN_OP_RETURN (EPLUS, false); } +".-" { BIN_OP_RETURN (EMINUS, false); } +".*" { BIN_OP_RETURN (EMUL, false); } +"./" { BIN_OP_RETURN (EDIV, false); } +".\\" { BIN_OP_RETURN (ELEFTDIV, false); } +{EPOW} { BIN_OP_RETURN (EPOW, false); } +".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true); } +"++" { do_comma_insert_check (); BIN_OP_RETURN (PLUS_PLUS, true); } +"--" { do_comma_insert_check (); BIN_OP_RETURN (MINUS_MINUS, true); } +"<=" { BIN_OP_RETURN (EXPR_LE, false); } +"==" { BIN_OP_RETURN (EXPR_EQ, false); } +{NOTEQ} { BIN_OP_RETURN (EXPR_NE, false); } +">=" { BIN_OP_RETURN (EXPR_GE, false); } +"|" { BIN_OP_RETURN (EXPR_OR, false); } +"&" { BIN_OP_RETURN (EXPR_AND, false); } +"<" { BIN_OP_RETURN (EXPR_LT, false); } +">" { BIN_OP_RETURN (EXPR_GT, false); } +"*" { BIN_OP_RETURN ('*', false); } +"/" { BIN_OP_RETURN ('/', false); } +"\\" { BIN_OP_RETURN (LEFTDIV, false); } +";" { BIN_OP_RETURN (';', true); } +"," { BIN_OP_RETURN (',', true); } +{POW} { BIN_OP_RETURN (POW, false); } +"=" { BIN_OP_RETURN ('=', true); } +"||" { BIN_OP_RETURN (EXPR_OR_OR, false); } +"&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } {NOT} { if (lexer_flags.plotting && ! lexer_flags.in_plot_range) - lexer_flags.past_plot_range = 1; - BIN_OP_RETURN (EXPR_NOT, 0); + lexer_flags.past_plot_range = true; + BIN_OP_RETURN (EXPR_NOT, false); } "+" { if (lexer_flags.plotting && ! lexer_flags.in_plot_range) - lexer_flags.past_plot_range = 1; - BIN_OP_RETURN ('+', 0); + lexer_flags.past_plot_range = true; + BIN_OP_RETURN ('+', false); } "-" { if (lexer_flags.plotting && ! lexer_flags.in_plot_range) - lexer_flags.past_plot_range = 1; - BIN_OP_RETURN ('-', 0); + lexer_flags.past_plot_range = true; + BIN_OP_RETURN ('-', false); } "(" { if (lexer_flags.plotting && ! lexer_flags.in_plot_range) - lexer_flags.past_plot_range = 1; + lexer_flags.past_plot_range = true; nesting_level.paren (); promptflag--; TOK_RETURN ('('); @@ -616,8 +616,8 @@ nesting_level.remove (); current_input_column++; - lexer_flags.cant_be_identifier = 1; - lexer_flags.quote_is_transpose = 1; + lexer_flags.cant_be_identifier = true; + lexer_flags.quote_is_transpose = true; lexer_flags.convert_spaces_to_comma = nesting_level.is_brace (); do_comma_insert_check (); return ')'; @@ -908,12 +908,12 @@ } else if (almost_match ("using", t)) { - lexer_flags.in_plot_using = 1; + lexer_flags.in_plot_using = true; return USING; } else if (almost_match ("with", t)) { - lexer_flags.in_plot_style = 1; + lexer_flags.in_plot_style = true; return WITH; } else if (strcmp ("clear", t) == 0) @@ -937,7 +937,7 @@ if (! sty.empty ()) { - lexer_flags.in_plot_style = 0; + lexer_flags.in_plot_style = false; yylval.tok_val = new token (sty); token_stack.push (yylval.tok_val); return STYLE; @@ -1017,17 +1017,17 @@ break; case gplot_kw: - lexer_flags.plotting = 1; + lexer_flags.plotting = true; yylval.tok_val = new token (token::two_dee, l, c); break; case gsplot_kw: - lexer_flags.plotting = 1; + lexer_flags.plotting = true; yylval.tok_val = new token (token::three_dee, l, c); break; case replot_kw: - lexer_flags.plotting = 1; + lexer_flags.plotting = true; yylval.tok_val = new token (token::replot, l, c); break; @@ -1050,9 +1050,9 @@ { tmp_local_sym_tab = new symbol_table (); curr_sym_tab = tmp_local_sym_tab; - lexer_flags.defining_func = 1; + lexer_flags.defining_func = true; promptflag--; - lexer_flags.beginning_of_function = 1; + lexer_flags.beginning_of_function = true; if (! (reading_fcn_file || reading_script_file)) input_line_number = 1; } @@ -1160,16 +1160,16 @@ // Return 1 if the given character matches any character in the given // string. -static int +static bool match_any (char c, const char *s) { char tmp; while ((tmp = *s++) != '\0') { if (c == tmp) - return 1; + return true; } - return 0; + return false; } // Given information about the spacing surrounding an operator, @@ -1178,7 +1178,7 @@ // // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary -static int +static bool looks_like_bin_op (int spc_prev, int spc_next) { return ((spc_prev && spc_next) || ! spc_prev); @@ -1187,10 +1187,10 @@ // Try to determine if the next token should be treated as a postfix // unary operator. This is ugly, but it seems to do the right thing. -static int +static bool next_token_is_postfix_unary_op (int spc_prev, char *yytext) { - int un_op = 0; + bool un_op = false; int c0 = yyinput (); int c1 = yyinput (); @@ -1227,10 +1227,10 @@ // // However, we still do check for `.+', `.*', etc. -static int +static bool next_token_is_bin_op (int spc_prev, char *yytext) { - int bin_op = 0; + bool bin_op = false; int c0 = yyinput (); @@ -1266,7 +1266,7 @@ case '~': case '!': case '=': - bin_op = 1; + bin_op = true; break; default: @@ -1305,7 +1305,7 @@ eat_whitespace (void) { yum_yum retval = ATE_NOTHING; - int in_comment = 0; + bool in_comment = false; int c; while ((c = yyinput ()) != EOF) { @@ -1320,13 +1320,13 @@ case '\n': retval |= ATE_NEWLINE; - in_comment = 0; + in_comment = false; current_input_column = 0; break; case '#': case '%': - in_comment = 1; + in_comment = true; break; case '.': @@ -1410,12 +1410,12 @@ // If non-whitespace characters are found before comment // characters, return 0. Otherwise, return 1. -static int +static bool have_continuation (int trailing_comments_ok) { ostrstream buf; - int in_comment = 0; + bool in_comment = false; char c; while ((c = yyinput ()) != EOF) { @@ -1430,7 +1430,7 @@ case '%': case '#': if (trailing_comments_ok) - in_comment = 1; + in_comment = true; else goto cleanup; break; @@ -1438,7 +1438,7 @@ case '\n': current_input_column = 0; promptflag--; - return 1; + return true; default: if (! in_comment) @@ -1448,7 +1448,7 @@ } yyunput (c, yytext); - return 0; + return false; cleanup: buf << ends; @@ -1460,14 +1460,14 @@ yyunput (s[len], yytext); } delete [] s; - return 0; + return false; } // We have seen a `.' and need to see if it is the start of a // continuation. If so, this eats it, up to and including the new // line character. -static int +static bool have_ellipsis_continuation (int trailing_comments_ok) { char c1 = yyinput (); @@ -1475,7 +1475,7 @@ { char c2 = yyinput (); if (c2 == '.' && have_continuation (trailing_comments_ok)) - return 1; + return true; else { yyunput (c2, yytext); @@ -1485,7 +1485,7 @@ else yyunput (c1, yytext); - return 0; + return false; } // See if we have a continuation line. If so, eat it and the leading @@ -1580,9 +1580,9 @@ } else { - lexer_flags.quote_is_transpose = 1; - lexer_flags.cant_be_identifier = 1; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = true; + lexer_flags.cant_be_identifier = true; + lexer_flags.convert_spaces_to_comma = true; } yylval.tok_val = new token (tok); @@ -1618,9 +1618,9 @@ int c1 = yyinput (); if (c1 == '=') { - lexer_flags.quote_is_transpose = 0; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; int c2 = yyinput (); unput (c2); @@ -1653,9 +1653,9 @@ } } - lexer_flags.quote_is_transpose = 1; - lexer_flags.cant_be_identifier = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = true; + lexer_flags.cant_be_identifier = false; + lexer_flags.convert_spaces_to_comma = true; return ']'; } @@ -1696,7 +1696,7 @@ // directly by another identifier. Special cases are handled // below. - lexer_flags.cant_be_identifier = 1; + lexer_flags.cant_be_identifier = true; // If we are expecting a structure element, we just want to return // TEXT_ID, which is a string that is also a valid identifier. But @@ -1711,9 +1711,9 @@ token_stack.push (yylval.tok_val); - lexer_flags.cant_be_identifier = 0; - lexer_flags.quote_is_transpose = 1; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.cant_be_identifier = false; + lexer_flags.quote_is_transpose = true; + lexer_flags.convert_spaces_to_comma = true; current_input_column += yyleng; @@ -1730,8 +1730,8 @@ if (kw_token == STYLE) { current_input_column += yyleng; - lexer_flags.quote_is_transpose = 0; - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.quote_is_transpose = false; + lexer_flags.convert_spaces_to_comma = true; return kw_token; } else @@ -1748,7 +1748,7 @@ // the square brackets that surround the range. if (! lexer_flags.in_plot_range) - lexer_flags.past_plot_range = 1; + lexer_flags.past_plot_range = true; // Option keywords can't appear in parentheses or braces. @@ -1792,7 +1792,7 @@ else if (! next_tok_is_paren) { if (tok == "gset") - lexer_flags.doing_set = 1; + lexer_flags.doing_set = true; BEGIN TEXT_FCN; } @@ -1809,7 +1809,7 @@ // After seeing an identifer, it is ok to convert spaces to a comma // (if needed). - lexer_flags.convert_spaces_to_comma = 1; + lexer_flags.convert_spaces_to_comma = true; // If we are defining a function and we have not seen the parameter // list yet and the next token is `=', return a token that @@ -1834,7 +1834,7 @@ // allow a following `'' to be treated as a transpose (the next // token is `=', so it can't be `''. - lexer_flags.quote_is_transpose = 1; + lexer_flags.quote_is_transpose = true; do_comma_insert_check (); maybe_unput_comma (spc_gobbled); @@ -1854,7 +1854,7 @@ // force the parser to return after reading the function. Calling // yyunput with EOF seems not to work... - int in_comment = 0; + bool in_comment = false; int lineno = input_line_number; int c; while ((c = yyinput ()) != EOF) @@ -1869,12 +1869,12 @@ case '\n': if (in_comment) - in_comment = 0; + in_comment = false; break; case '%': case '#': - in_comment = 1; + in_comment = true; break; default: @@ -1896,45 +1896,45 @@ void lexical_feedback::init (void) { - // Not initially defining a function. - beginning_of_function = 0; - defining_func = 0; - - // Not parsing a function return or parameter list. - looking_at_return_list = 0; - looking_at_parameter_list = 0; - // Not initially defining a matrix list. braceflag = 0; - // Next token can be identifier. - cant_be_identifier = 0; - - // No need to do comma insert or convert spaces to comma at - // beginning of input. - convert_spaces_to_comma = 1; - do_comma_insert = 0; - - // Not initially doing any plotting or setting of plot attributes. - doing_set = 0; - in_plot_range = 0; - in_plot_style = 0; - in_plot_using = 0; - past_plot_range = 0; - plotting = 0; - // Not initially inside a loop or if statement. looping = 0; + // Not initially defining a function. + beginning_of_function = false; + defining_func = false; + + // Not parsing a function return or parameter list. + looking_at_return_list = false; + looking_at_parameter_list = false; + + // Next token can be identifier. + cant_be_identifier = false; + + // No need to do comma insert or convert spaces to comma at + // beginning of input. + convert_spaces_to_comma = true; + do_comma_insert = false; + + // Not initially doing any plotting or setting of plot attributes. + doing_set = false; + in_plot_range = false; + in_plot_style = false; + in_plot_using = false; + past_plot_range = false; + plotting = false; + // Not initially looking at indirect references. - looking_at_indirect_ref = 0; + looking_at_indirect_ref = false; // Not initially screwed by `function [...] = f (...)' syntax. - maybe_screwed = 0; + maybe_screwed = false; maybe_screwed_again = 0; // Quote marks strings intially. - quote_is_transpose = 0; + quote_is_transpose = false; } int diff --git a/src/parse.y b/src/parse.y --- a/src/parse.y +++ b/src/parse.y @@ -107,7 +107,7 @@ (const char *type, token::end_tok_type ettype, int l, int c); // Check to see that end tokens are properly matched. -static int check_end (token *tok, token::end_tok_type expected); +static bool end_token_ok (token *tok, token::end_tok_type expected); // Try to figure out early if an expression should become an // assignment to the built-in variable ans. @@ -457,7 +457,7 @@ list1 : statement { - lexer_flags.beginning_of_function = 0; + lexer_flags.beginning_of_function = false; $$ = new tree_statement_list ($1); } | list1 sep statement @@ -563,12 +563,12 @@ using : using1 { - lexer_flags.in_plot_using = 0; + lexer_flags.in_plot_using = false; $$ = $1; } | using1 expression { - lexer_flags.in_plot_using = 0; + lexer_flags.in_plot_using = false; $$ = $1->set_format ($2); } ; @@ -900,7 +900,7 @@ ; in_return_list : // empty - { lexer_flags.looking_at_return_list = 1; } + { lexer_flags.looking_at_return_list = true; } ; local_symtab : // empty @@ -908,23 +908,23 @@ ; safe : // empty - { lexer_flags.maybe_screwed = 0; } + { lexer_flags.maybe_screwed = false; } ; are_we_screwed : // empty - { lexer_flags.maybe_screwed = 1; } + { lexer_flags.maybe_screwed = true; } ; func_def : FCN g_symtab are_we_screwed func_def1 { curr_sym_tab = top_level_sym_tab; - lexer_flags.defining_func = 0; + lexer_flags.defining_func = false; $$ = 0; } | FCN g_symtab are_we_screwed func_def2 { curr_sym_tab = top_level_sym_tab; - lexer_flags.defining_func = 0; + lexer_flags.defining_func = false; $$ = 0; } ; @@ -940,24 +940,24 @@ return_list : return_list_x ']' { - lexer_flags.looking_at_return_list = 0; + lexer_flags.looking_at_return_list = false; $$ = new tree_parameter_list (); } | return_list_x ELLIPSIS ']' { - lexer_flags.looking_at_return_list = 0; + lexer_flags.looking_at_return_list = false; tree_parameter_list *tmp = new tree_parameter_list (); tmp->mark_varargs_only (); $$ = tmp; } | return_list1 ']' { - lexer_flags.looking_at_return_list = 0; + lexer_flags.looking_at_return_list = false; $$ = $1; } | return_list1 ',' ELLIPSIS ']' { - lexer_flags.looking_at_return_list = 0; + lexer_flags.looking_at_return_list = false; $1->mark_varargs (); $$ = $1; } @@ -993,11 +993,13 @@ fcn_end_or_eof : END { - if (check_end ($1, token::function_end)) + if (end_token_ok ($1, token::function_end)) + { + if (reading_fcn_file) + check_for_garbage_after_fcn_def (); + } + else ABORT_PARSE; - - if (reading_fcn_file) - check_for_garbage_after_fcn_def (); } | END_OF_INPUT { @@ -1008,7 +1010,7 @@ indirect_ref : indirect_ref1 { - lexer_flags.looking_at_indirect_ref = 0; + lexer_flags.looking_at_indirect_ref = false; $$ = $1; } @@ -1018,7 +1020,7 @@ $1->column ()); } | indirect_ref1 '.' - { lexer_flags.looking_at_indirect_ref = 1; } TEXT_ID + { lexer_flags.looking_at_indirect_ref = true; } TEXT_ID { $$ = new tree_indirect_ref ($1, $4->text ()); } ; @@ -1038,34 +1040,34 @@ ; param_list_beg : '(' - { lexer_flags.looking_at_parameter_list = 1; } + { lexer_flags.looking_at_parameter_list = true; } ; param_list_end : ')' - { lexer_flags.looking_at_parameter_list = 0; } + { lexer_flags.looking_at_parameter_list = false; } ; param_list : param_list_beg param_list_end { - lexer_flags.quote_is_transpose = 0; + lexer_flags.quote_is_transpose = false; $$ = 0; } | param_list_beg ELLIPSIS param_list_end { - lexer_flags.quote_is_transpose = 0; + lexer_flags.quote_is_transpose = false; tree_parameter_list *tmp = new tree_parameter_list (); tmp->mark_varargs_only (); $$ = tmp; } | param_list1 param_list_end { - lexer_flags.quote_is_transpose = 0; + lexer_flags.quote_is_transpose = false; $1->mark_as_formal_parameters (); $$ = $1; } | param_list1 ',' ELLIPSIS param_list_end { - lexer_flags.quote_is_transpose = 0; + lexer_flags.quote_is_transpose = false; $1->mark_as_formal_parameters (); $1->mark_varargs (); $$ = $1; @@ -1298,12 +1300,17 @@ // Check to see that end tokens are properly matched. -static int -check_end (token *tok, token::end_tok_type expected) +static bool +end_token_ok (token *tok, token::end_tok_type expected) { + bool retval = true; + token::end_tok_type ettype = tok->ettype (); + if (ettype != expected && ettype != token::simple_end) { + retval = false; + yyerror ("parse error"); int l = tok->line (); @@ -1343,10 +1350,9 @@ panic_impossible (); break; } - return 1; } - else - return 0; + + return retval; } // Try to figure out early if an expression should become an @@ -1432,11 +1438,11 @@ return 0; } - lexer_flags.plotting = 0; - lexer_flags.past_plot_range = 0; - lexer_flags.in_plot_range = 0; - lexer_flags.in_plot_using = 0; - lexer_flags.in_plot_style = 0; + lexer_flags.plotting = false; + lexer_flags.past_plot_range = false; + lexer_flags.in_plot_range = false; + lexer_flags.in_plot_using = false; + lexer_flags.in_plot_style = false; return new tree_plot_command (list, range, tok->pttype ()); } @@ -1843,7 +1849,7 @@ { tree_command *retval = 0; - if (! check_end (end_tok, token::unwind_protect_end)) + if (end_token_ok (end_tok, token::unwind_protect_end)) { int l = unwind_tok->line (); int c = unwind_tok->column (); @@ -1862,7 +1868,7 @@ { tree_command *retval = 0; - if (! check_end (end_tok, token::try_catch_end)) + if (end_token_ok (end_tok, token::try_catch_end)) { int l = try_tok->line (); int c = try_tok->column (); @@ -1883,7 +1889,7 @@ maybe_warn_assign_as_truth_value (expr); - if (! check_end (end_tok, token::while_end)) + if (end_token_ok (end_tok, token::while_end)) { lexer_flags.looping--; @@ -1905,7 +1911,7 @@ { tree_command *retval = 0; - if (! check_end (end_tok, token::for_end)) + if (end_token_ok (end_tok, token::for_end)) { lexer_flags.looping--; @@ -1927,7 +1933,7 @@ { tree_command *retval = 0; - if (! check_end (end_tok, token::for_end)) + if (end_token_ok (end_tok, token::for_end)) { lexer_flags.looping--; @@ -2016,7 +2022,7 @@ { tree_if_command *retval = 0; - if (! check_end (end_tok, token::if_end)) + if (end_token_ok (end_tok, token::if_end)) { int l = if_tok->line (); int c = if_tok->column (); @@ -2045,7 +2051,7 @@ { tree_switch_command *retval = 0; - if (! check_end (end_tok, token::switch_end)) + if (end_token_ok (end_tok, token::switch_end)) { int l = switch_tok->line (); int c = switch_tok->column ();