Mercurial > hg > octave-nkf
diff libinterp/parse-tree/lex.h @ 16149:49dfba4fd3c5
use pure parser and reentrant lexer interfaces
Making the Octave parser and lexer properly reentrant (and perhaps
eventually thread safe as well) is still a work in progress. With the
current set of changes the parser and lexer still use many global
variables, so these changes alone do NOT make the Octave parser
reentrant unless you take care to properly save and restore (typically
with an unwind_protect object) relevant global values before and after
calling the parser. Even if global variables are properly saved and
restored, the parser will NOT be thread safe.
* lex.ll: Use %option reentrant an %option bison-bridge.
(yylval): Delete macro.
(YY_EXTRA_TYPE, curr_lexer): New macros. Undefine curr_lexer
(YY_FATAL_ERROR): Update decl for reentrant scanner.
(lexical_feedback::reset): Update call to yyrestart for reentrant
scanner interface.
(lexical_feedback::fatal_error): Update call to yy_fatal_error for
reentrant scanner interface.
(lexical_feedback::text_yyinput): Update calls to yyinput and yyunput
for reentrant scanner interface.
(lexical_feedback::flex_yyleng): Use function interface to access
yyleng.
(lexical_feedback::flex_yytext): Use function interface to access
yytext.
(lexical_feedback::push_token, lexical_feedback::current_token):
Use function interface to access yylval.
* oct-parse.yy: Use %define api.pure, %parse-param, and %lex-param
options.
(curr_lexer): Define for syntax rules section.
(scanner): New macro.
* oct-parse.yy: Include oct-parse.h.
(octave_lex): Declare.
(yyerror): Update declaration for pure parser.
* parse.h (octave_lex): Delete decl.
* oct-parse.yy (octave_parser::run): Pass pointer to octave_parser
object to octave_parse.
* lex.ll (lexical_feedback::octave_read): Call fatal_error directly
instead of using YY_FATAL_ERROR.
* oct-parse.yy (parse_fcn_file): Pass line and column info for lexter
to gobble_leading_whitespace. Access prep_for_script_file,
prep_for_function_file, parsing_class_method, input_line_number, and
current_input_column through curr_parser.
* parse.h, oct-parse.yy (YY_BUFFER_STATE, create_buffer,
current_buffer, switch_to_buffer, delete_buffer, clear_all_buffers):
Delete.
* toplev.cc (main_loop): Don't create new buffer for lexer.
* input.cc (get_debug_input): Likewise.
* oct-parse.yy (eval_string, parse_fcn_file): Likewise.
* octave.cc (octave_initialize_interpreter): Likewise.
* input.cc (get_debug_input): Likewise.
* oct-parse.yy (eval_string, parse_fcn_file): Create parser as needed.
* octave.cc (octave_initialize_interpreter): Likewise.
* input.cc (get_debug_input): Likewise.
* input.cc (input_even_hook): Allow function to run even if currently
defining a function.
* lex.h, lex.ll (curr_lexer): Delete global variable.
* parse.h, oct-parse.yy (octave_parser::curr_lexer): New data member.
(octave_parser::octave_parser): Create lexer here.
(curr_parser): Delete global variable.
* toplev.cc (main_loop): Don't protect global curr_lexer and
curr_parser variables.
* oct-parse.yy (eval_string, parse_fcn_file): Likewise.
* input.cc (get_debug_input): Likewise.
* lex.h, lex.ll (curr_lexer): Delete global variable.
* parse.h, oct-parse.yy (CURR_LEXER): New temporary global.
(octave_parser::octave_parser): Set global CURR_LEXER here.
* toplev.cc (main_loop): Protect CURR_LEXER prior to constructing
new parser object.
* input.cc (get_debug_input): Likewise.
* oct-parse.yy (eval_string, parse_fcn_file): Likewise.
* lex.h, lex.ll (lexical_feedback::scanner): New data member.
(lexical_feedback::init): Create it. Call yylex_set_extra to store
pointer to lexical_feedback object in scanner data.
(lexical_feedback::~lexical_feedback): Delete it.
* lex.ll (YYG): New macro.
(lexical_feedback::reset, lexical_feedback::prep_for_script_file,
lexical_feedback::prep_for_function_file,
lexical_feedback::process_comment,
lexical_feedback::handle_close_bracket,
lexical_feedback::handle_identifier, lexical_feedback::lexer_debug):
Use it to access scanner data.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 27 Feb 2013 18:49:16 -0500 |
parents | 2fd39ab12209 |
children | 0259254a3ccc 7eb614760ddb |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -27,25 +27,6 @@ #include <set> #include <stack> -// FIXME -- these input buffer things should be members of a -// parser input stream class. - -typedef struct yy_buffer_state *YY_BUFFER_STATE; - -// Associate a buffer with a new file to read. -extern OCTINTERP_API YY_BUFFER_STATE create_buffer (FILE *f); - -// Report the current buffer. -extern OCTINTERP_API YY_BUFFER_STATE current_buffer (void); - -// Connect to new buffer buffer. -extern OCTINTERP_API void switch_to_buffer (YY_BUFFER_STATE buf); - -// Delete a buffer. -extern OCTINTERP_API void delete_buffer (YY_BUFFER_STATE buf); - -extern OCTINTERP_API void clear_all_buffers (void); - extern OCTINTERP_API void cleanup_parser (void); // Is the given string a keyword? @@ -173,8 +154,8 @@ }; lexical_feedback (void) - : convert_spaces_to_comma (true), do_comma_insert (false), - at_beginning_of_statement (true), + : scanner (0), convert_spaces_to_comma (true), + do_comma_insert (false), at_beginning_of_statement (true), looking_at_anon_fcn_args (false), looking_at_return_list (false), looking_at_parameter_list (false), looking_at_decl_list (false), looking_at_initializer_expression (false), @@ -195,12 +176,7 @@ ~lexical_feedback (void); - void init (void) - { - // The closest paren, brace, or bracket nesting is not an object - // index. - looking_at_object_index.push_front (false); - } + void init (void); void reset (void); @@ -297,6 +273,9 @@ void lexer_debug (const char *pattern, const char *text); + // Internal state of the flex-generated lexer. + void *scanner; + // TRUE means that we should convert spaces to a comma inside a // matrix definition. bool convert_spaces_to_comma; @@ -407,7 +386,4 @@ lexical_feedback& operator = (const lexical_feedback&); }; -// The current state of the lexer. -extern lexical_feedback *curr_lexer; - #endif