# HG changeset patch # User John W. Eaton # Date 1452767736 18000 # Node ID 202cfd2b45149719f1a87c209a4cb73498c1b6c2 # Parent d9c1884d1aaab0322570e7f19c75d4724b4af106 store parser state in base class; use it in push and pull parsers * parse.h, oct-parse.in.yy (octave_base_parser::parser_state): Move here from octave_push_parser class. (octave_base_parser::octave_base_parser): Initialize parser_state in initializer list. (octave_base_parser::~octave_base_parser): Delete parser_state. (octave_base_parser::reset): Delete and re-create parser_state. (octave_push_parser::init): Delete method and all uses. (octave_push_parser::~octave_push_parser): Don't delete parser_state. diff -r d9c1884d1aaa -r 202cfd2b4514 libinterp/parse-tree/oct-parse.in.yy --- a/libinterp/parse-tree/oct-parse.in.yy Wed Jan 13 22:30:10 2016 -0800 +++ b/libinterp/parse-tree/oct-parse.in.yy Thu Jan 14 05:35:36 2016 -0500 @@ -2029,11 +2029,30 @@ parser.bison_error (s); } +octave_base_parser::octave_base_parser (octave_base_lexer& lxr) + : endfunction_found (false), autoloading (false), + fcn_file_from_relative_lookup (false), parsing_subfunctions (false), + max_fcn_depth (0), curr_fcn_depth (0), primary_fcn_scope (-1), + curr_class_name (), curr_package_name (), function_scopes (), + primary_fcn_ptr (0), subfunction_names (), classdef_object (0), + stmt_list (0), lexer (lxr), parser_state (yypstate_new ()) +{ } + octave_base_parser::~octave_base_parser (void) { delete stmt_list; delete &lexer; + + // FIXME: Deleting the internal Bison parser state structure does + // not clean up any partial parse trees in the event of an interrupt or + // error. It's not clear how to safely do that with the C language + // parser that Bison generates. The C++ language parser that Bison + // generates would do it for us automatically whenever an exception + // is thrown while parsing input, but there is currently no C++ + // interface for a push parser. + + yypstate_delete (static_cast (parser_state)); } void @@ -2056,6 +2075,9 @@ stmt_list = 0; lexer.reset (); + + yypstate_delete (static_cast (parser_state)); + parser_state = yypstate_new (); } // Error mesages for mismatched end tokens. @@ -4004,17 +4026,6 @@ return octave_parse (*this); } -octave_push_parser::~octave_push_parser (void) -{ - yypstate_delete (static_cast (parser_state)); -} - -void -octave_push_parser::init (void) -{ - parser_state = yypstate_new (); -} - // Parse input from INPUT. Pass TRUE for EOF if the end of INPUT should // finish the parse. diff -r d9c1884d1aaa -r 202cfd2b4514 libinterp/parse-tree/parse.h --- a/libinterp/parse-tree/parse.h Wed Jan 13 22:30:10 2016 -0800 +++ b/libinterp/parse-tree/parse.h Thu Jan 14 05:35:36 2016 -0500 @@ -145,22 +145,14 @@ { public: - octave_base_parser (octave_base_lexer& lxr) - : endfunction_found (false), - autoloading (false), fcn_file_from_relative_lookup (false), - parsing_subfunctions (false), max_fcn_depth (0), - curr_fcn_depth (0), primary_fcn_scope (-1), - curr_class_name (), curr_package_name (), function_scopes (), - primary_fcn_ptr (0), subfunction_names (), classdef_object (0), - stmt_list (0), lexer (lxr) - { } + octave_base_parser (octave_base_lexer& lxr); ~octave_base_parser (void); void reset (void); // Error mesages for mismatched end tokens. - void end_error (const char *type, token::end_tok_type ettype, int l, int c); + void end_error (const char *type, token::end_tok_type expected, int l, int c); // Check to see that end tokens are properly matched. bool end_token_ok (token *tok, token::end_tok_type expected); @@ -458,6 +450,9 @@ // State of the lexer. octave_base_lexer& lexer; + // Internal state of the Bison parser. + void *parser_state; + private: // No copying! @@ -507,22 +502,15 @@ public: octave_push_parser (void) - : octave_base_parser (*(new octave_push_lexer ())), parser_state (0) - { - init (); - } + : octave_base_parser (*(new octave_push_lexer ())) + { } - ~octave_push_parser (void); - - void init (void); + ~octave_push_parser (void) { } int run (const std::string& input, bool eof); private: - // Internal state of the Bison parser. - void *parser_state; - // No copying! octave_push_parser (const octave_push_parser&);