Hi! > Le 19 août 2018 à 18:21, Rici Lake <[email protected]> a écrit : > > Vaguely on this topic, since you seem to be working on a new release:
Yup. > On Sun, Aug 19, 2018, 10:23 Akim Demaille <[email protected]> wrote: > >> >> Note that you don’t have anything to do to reset the parser, all the >> problem is actually the scanner. The parser object holds no state, >> everything is local to yyparse. >> > > That's not the case for a push parser (which unfortunately is not an option > in C++ or Java.) I agree, push parsers are really nice. It’s too bad history has put so much focus on pull. If you want to submit push parsers for C++/Java, be sure to expect enthousiasme on my side :) > As it happens, that's my preferred API, and at some point > I needed to convince myself that it was unnecessary to reset the parser > state "object". > > Since this fact is not documented, it is presumably unspecified whether any > guarantee will be maintained. I think it's a useful guarantee, and since it > is already implemented it might as well be documented, by adding something > like the following paragraph to the end of section 4.2: > >> After yypush_parse returns a status other than YYPUSH_MORE, the parser > instance yyps may be reused for a new parse. > > I guess a similar guarantee could be provided in the documentation for > yypull_parse (without mention of YYPUSH_MORE), since that is just a thin > wrapper around yypush_parse. See below. > --- > > The fact that the parser state is reusable even after an error simplifies > reuse. For example, a calculator application which parses each input line > as an expression can just keep reusing the same pstate even if an input was > invalid. (The scanner will need to be reset but that's not bison's problem.) Too good to be left in the mailing list archive. WDYT? commit 7ff6b7bbcab88ce667d97ae37171a9cfc9ec8d66 Author: Akim Demaille <[email protected]> Date: Sun Aug 19 20:53:59 2018 +0200 doc: clarify that the push parser object can be reused Suggested by Rici Lake. https://lists.gnu.org/archive/html/bug-bison/2018-08/msg00033.html * doc/bison.texi: Complete description of the first node in the main @menu. (Push Decl): Remove the 'experimental' warnings about push parser. Clarify that the push parser object can be reused in several parses. diff --git a/doc/bison.texi b/doc/bison.texi index b463588b..9eff2886 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -86,8 +86,8 @@ Cover art by Etienne Suvasa. @end ifnottex @menu -* Introduction:: -* Conditions:: +* Introduction:: What GNU Bison is. +* Conditions:: Conditions for using Bison and its output. * Copying:: The GNU General Public License says how you can copy and share Bison. @@ -5327,9 +5327,6 @@ valid grammar. @cindex push parser @findex %define api.push-pull -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) - A pull parser is called once and it takes control until all its input is completely parsed. A push parser, on the other hand, is called each time a new token is made available. @@ -5907,8 +5904,6 @@ the @code{full} value was introduced in Bison 2.7 @item Purpose: Request a pull parser, a push parser, or both. @xref{Push Decl, ,A Push Parser}. -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) @item Accepted Values: @code{pull}, @code{push}, @code{both} @@ -6588,27 +6583,29 @@ int yyparse (int *randomness); @section The Push Parser Function @code{yypush_parse} @findex yypush_parse -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) - You call the function @code{yypush_parse} to parse a single token. This function is available if either the @samp{%define api.push-pull push} or @samp{%define api.push-pull both} declaration is used. @xref{Push Decl, ,A Push Parser}. @deftypefun int yypush_parse (yypstate *@var{yyps}) -The value returned by @code{yypush_parse} is the same as for yyparse with -the following exception: it returns @code{YYPUSH_MORE} if more input is +The value returned by @code{yypush_parse} is the same as for @code{yyparse} +with the following exception: it returns @code{YYPUSH_MORE} if more input is required to finish parsing the grammar. + +After @code{yypush_parse} returns a status other than @code{YYPUSH_MORE}, +the parser instance @code{yyps} may be reused for a new parse. @end deftypefun +The fact that the parser state is reusable even after an error simplifies +reuse. For example, a calculator application which parses each input line +as an expression can just keep reusing the same @code{yyps} even if an input +was invalid. + @node Pull Parser Function @section The Pull Parser Function @code{yypull_parse} @findex yypull_parse -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) - You call the function @code{yypull_parse} to parse the rest of the input stream. This function is available if the @samp{%define api.push-pull both} declaration is used. @@ -6616,15 +6613,14 @@ declaration is used. @deftypefun int yypull_parse (yypstate *@var{yyps}) The value returned by @code{yypull_parse} is the same as for @code{yyparse}. + +The parser instance @code{yyps} may be reused for new parses. @end deftypefun @node Parser Create Function @section The Parser Create Function @code{yystate_new} @findex yypstate_new -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) - You call the function @code{yypstate_new} to create a new parser instance. This function is available if either the @samp{%define api.push-pull push} or @samp{%define api.push-pull both} declaration is used. @@ -6641,9 +6637,6 @@ allocated. @section The Parser Delete Function @code{yystate_delete} @findex yypstate_delete -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) - You call the function @code{yypstate_delete} to delete a parser instance. function is available if either the @samp{%define api.push-pull push} or @samp{%define api.push-pull both} declaration is used. @@ -13187,8 +13180,6 @@ The function to delete a parser instance, produced by Bison in push mode; call this function to delete the memory associated with a parser. @xref{Parser Delete Function, ,The Parser Delete Function @code{yypstate_delete}}. Does nothing when called with a null pointer. -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) @end deffn @deffn {Function} yypstate_new @@ -13196,8 +13187,6 @@ The function to create a parser instance, produced by Bison in push mode; call this function to create a new parser. @xref{Parser Create Function, ,The Parser Create Function @code{yypstate_new}}. -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) @end deffn @deffn {Function} yypull_parse @@ -13205,16 +13194,12 @@ The parser function produced by Bison in push mode; call this function to parse the rest of the input stream. @xref{Pull Parser Function, ,The Pull Parser Function @code{yypull_parse}}. -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) @end deffn @deffn {Function} yypush_parse The parser function produced by Bison in push mode; call this function to parse a single token. @xref{Push Parser Function, ,The Push Parser Function @code{yypush_parse}}. -(The current push parsing interface is experimental and may evolve. -More user feedback will help to stabilize it.) @end deffn @deffn {Macro} YYRECOVERING
