Mercurial > hg > octave-nkf
diff libinterp/parse-tree/oct-parse.in.yy @ 17745:93b3d03b05e7 classdef
maint: periodic merge of default to classdef
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 23 Oct 2013 22:29:06 -0400 |
parents | dc4124992f0c d63878346099 |
children | 97e49b588f5d |
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.in.yy +++ b/libinterp/parse-tree/oct-parse.in.yy @@ -1,6 +1,6 @@ /* -Copyright (C) 1993-2012 John W. Eaton +Copyright (C) 1993-2013 John W. Eaton Copyright (C) 2009 David Grundberg Copyright (C) 2009-2010 VZLU Prague @@ -107,16 +107,6 @@ static void yyerror (octave_base_parser& parser, const char *s); -// Finish building a statement. -template <class T> -static tree_statement * -make_statement (T *arg) -{ - octave_comment_list *comment = octave_comment_buffer::get_comment (); - - return new tree_statement (arg, comment); -} - #define ABORT_PARSE \ do \ { \ @@ -136,6 +126,11 @@ // Bison declarations. +// The grammar currently has 14 shift/reduce conflicts. Ensure that +// we notice if that number changes. + +%expect 14 + // Don't add spaces around the = here; it causes some versions of // bison to fail to properly recognize the directive. @@ -418,11 +413,11 @@ ; statement : expression - { $$ = make_statement ($1); } + { $$ = parser.make_statement ($1); } | command - { $$ = make_statement ($1); } + { $$ = parser.make_statement ($1); } | word_list_cmd - { $$ = make_statement ($1); } + { $$ = parser.make_statement ($1); } ; // ================= @@ -1687,7 +1682,7 @@ ; stash_comment : // empty - { $$ = octave_comment_buffer::get_comment (); } + { $$ = lexer.get_comment (); } ; parse_error : LEXICAL_ERROR @@ -1762,11 +1757,6 @@ delete &lexer; } -void octave_base_parser::init (void) -{ - LEXER = &lexer; -} - void octave_base_parser::reset (void) { @@ -2447,7 +2437,7 @@ if (end_token_ok (end_tok, token::unwind_protect_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = unwind_tok->line (); int c = unwind_tok->column (); @@ -2479,7 +2469,7 @@ if (end_token_ok (end_tok, token::try_catch_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = try_tok->line (); int c = try_tok->column (); @@ -2499,6 +2489,9 @@ id = dynamic_cast<tree_identifier *> (expr); cleanup_stmts->pop_front (); + + stmt->set_expression (0); + delete stmt; } } } @@ -2530,7 +2523,7 @@ if (end_token_ok (end_tok, token::while_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); lexer.looping--; @@ -2558,7 +2551,7 @@ { maybe_warn_assign_as_truth_value (expr); - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); lexer.looping--; @@ -2585,7 +2578,7 @@ if (end_token_ok (end_tok, parfor ? token::parfor_end : token::for_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); lexer.looping--; @@ -2679,7 +2672,7 @@ if (end_token_ok (end_tok, token::if_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = if_tok->line (); int c = if_tok->column (); @@ -2732,7 +2725,7 @@ if (end_token_ok (end_tok, token::switch_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = switch_tok->line (); int c = switch_tok->column (); @@ -2916,7 +2909,7 @@ if (fcn) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); fcn->stash_trailing_comment (tc); fcn->stash_fcn_end_location (end_fcn_stmt->line (), @@ -3187,7 +3180,7 @@ bison_error ("invalid classdef definition, the class name must match the file name"); else if (end_token_ok (end_tok, token::classdef_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = tok_val->line (); int c = tok_val->column (); @@ -3218,7 +3211,7 @@ if (end_token_ok (end_tok, token::properties_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = tok_val->line (); int c = tok_val->column (); @@ -3245,7 +3238,7 @@ if (end_token_ok (end_tok, token::methods_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = tok_val->line (); int c = tok_val->column (); @@ -3272,7 +3265,7 @@ if (end_token_ok (end_tok, token::events_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = tok_val->line (); int c = tok_val->column (); @@ -3299,7 +3292,7 @@ if (end_token_ok (end_tok, token::enumeration_end)) { - octave_comment_list *tc = octave_comment_buffer::get_comment (); + octave_comment_list *tc = lexer.comment_buf.get_comment (); int l = tok_val->line (); int c = tok_val->column (); @@ -3649,6 +3642,16 @@ return list; } +// Finish building a statement. +template <class T> +tree_statement * +octave_base_parser::make_statement (T *arg) +{ + octave_comment_list *comment = lexer.get_comment (); + + return new tree_statement (arg, comment); +} + tree_statement_list * octave_base_parser::make_statement_list (tree_statement *stmt) { @@ -3729,8 +3732,6 @@ octave_push_parser::init (void) { parser_state = yypstate_new (); - - octave_base_parser::init (); } // Parse input from INPUT. Pass TRUE for EOF if the end of INPUT should @@ -3770,15 +3771,6 @@ static void safe_fclose (FILE *f) { - // FIXME -- comments at the end of an input file are - // discarded (otherwise, they would be appended to the next - // statement, possibly from the command line or another file, which - // can be quite confusing). - - octave_comment_list *tc = octave_comment_buffer::get_comment (); - - delete tc; - if (f) fclose (static_cast<FILE *> (f)); } @@ -4574,11 +4566,6 @@ { octave_value_list retval; - unwind_protect frame; - - // octave_base_parser constructor sets this for us. - frame.protect_var (LEXER); - octave_parser parser (eval_str); do @@ -4587,9 +4574,6 @@ parse_status = parser.run (); - // Unmark forced variables. - frame.run (1); - if (parse_status == 0) { if (parser.stmt_list)