Mercurial > hg > octave-nkf
comparison libinterp/parse-tree/parse.h @ 16287:04a7953496a7
create base class for parser; use reference for curr_lexer
* lex.h, lex.ll (octave_base_parser): New base class for parser
class. Move most of previous octave_parser class here. Use reference
for curr_lexer object instead of pointer. Change all uses.
(octave_parser): Derive from octave_base_parser.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 12 Mar 2013 00:18:28 -0400 |
parents | c5e5f6ccac5d |
children | fe3b9a51e625 |
comparison
equal
deleted
inserted
replaced
16285:3389152014ca | 16287:04a7953496a7 |
---|---|
124 // Global access to currently active lexer. | 124 // Global access to currently active lexer. |
125 // FIXME -- to be removed after more parser+lexer refactoring. | 125 // FIXME -- to be removed after more parser+lexer refactoring. |
126 extern octave_lexer *CURR_LEXER; | 126 extern octave_lexer *CURR_LEXER; |
127 | 127 |
128 class | 128 class |
129 octave_parser | 129 octave_base_parser |
130 { | 130 { |
131 public: | 131 public: |
132 | 132 |
133 octave_parser (void) | 133 octave_base_parser (octave_lexer& lxr) |
134 : endfunction_found (false), | 134 : endfunction_found (false), |
135 autoloading (false), fcn_file_from_relative_lookup (false), | 135 autoloading (false), fcn_file_from_relative_lookup (false), |
136 parsing_subfunctions (false), max_fcn_depth (0), | 136 parsing_subfunctions (false), max_fcn_depth (0), |
137 curr_fcn_depth (0), primary_fcn_scope (-1), | 137 curr_fcn_depth (0), primary_fcn_scope (-1), |
138 curr_class_name (), function_scopes (), primary_fcn_ptr (0), | 138 curr_class_name (), function_scopes (), primary_fcn_ptr (0), |
139 stmt_list (0), | 139 stmt_list (0), |
140 curr_lexer (new octave_lexer ()), parser_state (0) | 140 curr_lexer (lxr), parser_state (0) |
141 { | 141 { |
142 init (); | 142 init (); |
143 } | 143 } |
144 | 144 |
145 octave_parser (FILE *file) | 145 virtual ~octave_base_parser (void); |
146 : endfunction_found (false), | |
147 autoloading (false), fcn_file_from_relative_lookup (false), | |
148 parsing_subfunctions (false), max_fcn_depth (0), | |
149 curr_fcn_depth (0), primary_fcn_scope (-1), | |
150 curr_class_name (), function_scopes (), primary_fcn_ptr (0), | |
151 stmt_list (0), | |
152 curr_lexer (new octave_lexer (file)), parser_state (0) | |
153 { | |
154 init (); | |
155 } | |
156 | |
157 octave_parser (const std::string& eval_string) | |
158 : endfunction_found (false), | |
159 autoloading (false), fcn_file_from_relative_lookup (false), | |
160 parsing_subfunctions (false), max_fcn_depth (0), | |
161 curr_fcn_depth (0), primary_fcn_scope (-1), | |
162 curr_class_name (), function_scopes (), primary_fcn_ptr (0), | |
163 stmt_list (0), | |
164 curr_lexer (new octave_lexer (eval_string)), parser_state (0) | |
165 { | |
166 init (); | |
167 } | |
168 | |
169 ~octave_parser (void); | |
170 | 146 |
171 void init (void); | 147 void init (void); |
172 | 148 |
173 void reset (void); | 149 void reset (void); |
174 | |
175 int run (void); | |
176 | 150 |
177 // Error mesages for mismatched end tokens. | 151 // Error mesages for mismatched end tokens. |
178 void end_error (const char *type, token::end_tok_type ettype, int l, int c); | 152 void end_error (const char *type, token::end_tok_type ettype, int l, int c); |
179 | 153 |
180 // Check to see that end tokens are properly matched. | 154 // Check to see that end tokens are properly matched. |
405 | 379 |
406 // Result of parsing input. | 380 // Result of parsing input. |
407 tree_statement_list *stmt_list; | 381 tree_statement_list *stmt_list; |
408 | 382 |
409 // State of the lexer. | 383 // State of the lexer. |
410 octave_lexer *curr_lexer; | 384 octave_lexer& curr_lexer; |
411 | 385 |
412 // Internal state of the parser. Only used if USE_PUSH_PARSER is | 386 // Internal state of the parser. Only used if USE_PUSH_PARSER is |
413 // defined. | 387 // defined. |
414 void *parser_state; | 388 void *parser_state; |
415 | 389 |
416 // For unwind protect. | 390 private: |
417 static void cleanup (octave_parser *parser) { delete parser; } | 391 |
392 // No copying! | |
393 | |
394 octave_base_parser (const octave_base_parser&); | |
395 | |
396 octave_base_parser& operator = (const octave_base_parser&); | |
397 }; | |
398 | |
399 class | |
400 octave_parser : public octave_base_parser | |
401 { | |
402 public: | |
403 | |
404 octave_parser (void) | |
405 : octave_base_parser (*(new octave_lexer ())) | |
406 { } | |
407 | |
408 octave_parser (FILE *file) | |
409 : octave_base_parser (*(new octave_lexer (file))) | |
410 { } | |
411 | |
412 octave_parser (const std::string& eval_string) | |
413 : octave_base_parser (*(new octave_lexer (eval_string))) | |
414 { } | |
415 | |
416 ~octave_parser (void) { } | |
417 | |
418 int run (void); | |
418 | 419 |
419 private: | 420 private: |
420 | 421 |
421 // No copying! | 422 // No copying! |
422 | 423 |