Mercurial > hg > octave-lyh
changeset 16157:335041cc657a
optionally use push parser interface
* configure.ac (USE_PUSH_PARSER): New config variable. Display
setting in config summary. Provide --enable-push-parser option.
* oct-parse.yy: Use "%define api.push-pull both" bison option.
* parse.h, oct-parse.yy (octave_parser::parser_state): New member
variable.
(octave_parser::init): Initialize it if USE_PUSH_PARSER is defined.
(octave_parser::~octave_parser): Delete it if USE_PUSH_PARSER.
(octave_parser::run): Use push parser interface if USE_PUSH_PARSER.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 28 Feb 2013 10:53:27 -0500 |
parents | 236be6179785 |
children | 7eb614760ddb |
files | configure.ac libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/parse.h |
diffstat | 3 files changed, 79 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac +++ b/configure.ac @@ -190,6 +190,17 @@ AC_DEFINE(BOUNDS_CHECKING, 1, [Define to 1 to use internal bounds checking.]) fi +### Enable experimental push parser. + +OCTAVE_USE_PUSH_PARSER=no +AC_ARG_ENABLE([push-parser], + [AS_HELP_STRING([--enable-push-parser], + [enable experimental push parser])], + [if test "$enableval" = yes; then OCTAVE_USE_PUSH_PARSER=yes; fi], []) +if test $OCTAVE_USE_PUSH_PARSER = yes; then + AC_DEFINE(OCTAVE_USE_PUSH_PARSER, 1, [Define to 1 to use experimental push parser.]) +fi + ### Use Octave's built-in memory allocator rather than straightforward malloc. ### Disabled by default. @@ -2974,6 +2985,7 @@ Build Java interface: $build_java Do internal array bounds checking: $BOUNDS_CHECKING Use octave_allocator: $USE_OCTAVE_ALLOCATOR + Use push parser: $OCTAVE_USE_PUSH_PARSER Build static libraries: $STATIC_LIBS Build shared libraries: $SHARED_LIBS Dynamic Linking: $ENABLE_DYNAMIC_LINKING $DL_API_MSG
--- a/libinterp/parse-tree/oct-parse.yy +++ b/libinterp/parse-tree/oct-parse.yy @@ -166,6 +166,7 @@ // object) relevant global values before and after the nested call. %define api.pure +%define api.push-pull both %parse-param { octave_parser *curr_parser } %lex-param { void *scanner } @@ -1479,10 +1480,66 @@ curr_parser->bison_error (s); } +octave_parser::~octave_parser (void) +{ +#if defined (USE_PUSH_PARSER) + yypstate_delete (parser_state); +#endif + +delete curr_lexer; +} +void octave_parser::init (void) +{ +#if defined (USE_PUSH_PARSER) + parser_state = yypstate_new (); +#endif + + CURR_LEXER = curr_lexer; +} + int octave_parser::run (void) { - return octave_parse (this); + int status = 0; + +#if defined (USE_PUSH_PARSER) + + for (;;) + { + unwind_protect frame; + + frame.protect_var (current_input_line); + + bool eof = false; + + get_user_input (eof); + + do + { + octave_char = eof ? END_OF_INPUT : octave_lex (); + + if (octave_char == 0) + { + // Attempt to get more input. + status = -1; + break; + } + + status = octave_push_parse (pstate); + } + while (status == YYPUSH_MORE); + + if (status >= 0) + break; + } + +#else + + status = octave_parse (this); + +#endif + + return status; } // Error mesages for mismatched end tokens.
--- a/libinterp/parse-tree/parse.h +++ b/libinterp/parse-tree/parse.h @@ -144,15 +144,14 @@ parsing_subfunctions (false), max_fcn_depth (0), curr_fcn_depth (0), primary_fcn_scope (-1), curr_class_name (), function_scopes (), primary_fcn_ptr (0), - curr_lexer (new lexical_feedback ()) + curr_lexer (new lexical_feedback ()), parser_state (0) { - CURR_LEXER = curr_lexer; + init (); } - ~octave_parser (void) - { - delete curr_lexer; - } + ~octave_parser (void); + + void init (void); void reset (void) { @@ -389,6 +388,10 @@ // State of the lexer. lexical_feedback *curr_lexer; + // Internal state of the parser. Only used if USE_PUSH_PARSER is + // defined. + void *parser_state; + // For unwind protect. static void cleanup (octave_parser *parser) { delete parser; }