bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

06-destructor-doc.patch


From: Akim Demaille
Subject: 06-destructor-doc.patch
Date: Tue, 12 Nov 2002 08:44:29 +0100

Index: 0.9/ChangeLog
--- 0.9/ChangeLog Sun, 10 Nov 2002 11:08:56 +0100 akim (bison/d/40_ChangeLog 
1.7 644)
+++ 0.9(w)/ChangeLog Sun, 10 Nov 2002 14:43:35 +0100 akim (bison/d/40_ChangeLog 
1.7 644)
@@ -1,5 +1,9 @@
 2002-11-10  Akim Demaille  <address@hidden>
 
+       * doc/bison.texinfo (Destructor Decl): New.
+
+2002-11-10  Akim Demaille  <address@hidden>
+
        * src/tables.c (tables_generate): Use free for pointers that
        cannot be NULL, not XFREE.
        (pack_vector): Use assert, not fatal, for bound violations.
Index: 0.9/doc/bison.texinfo
--- 0.9/doc/bison.texinfo Sat, 09 Nov 2002 11:07:24 +0100 akim 
(bison/23_bison.texi 1.2 644)
+++ 0.9(w)/doc/bison.texinfo Sun, 10 Nov 2002 14:52:56 +0100 akim 
(bison/23_bison.texi 1.2 644)
@@ -208,6 +208,7 @@
 * Precedence Decl::   Declaring terminals with precedence and associativity.
 * Union Decl::        Declaring the set of all semantic value types.
 * Type Decl::         Declaring the choice of type for a nonterminal symbol.
+* Destructor Decl::   Declaring how symbols are freed.
 * Expect Decl::       Suppressing warnings about shift/reduce conflicts.
 * Start Decl::        Specifying the start symbol.
 * Pure Decl::         Requesting a reentrant parser.
@@ -1851,7 +1852,6 @@
 %right '^'    /* Exponentiation        */
 
 /* Grammar follows */
-
 %%
 @end smallexample
 
@@ -1928,7 +1928,9 @@
 @group
 /* Function type.                                    */
 typedef double (*func_t) (double);
address@hidden group
 
address@hidden
 /* Data type for links in the chain of symbols.      */
 struct symrec
 @{
@@ -2748,11 +2750,11 @@
 
 @cindex default action
 If you don't specify an action for a rule, Bison supplies a default:
address@hidden@code{$$ = $1}.}  Thus, the value of the first symbol in the rule 
becomes
-the value of the whole rule.  Of course, the default rule is valid only
-if the two data types match.  There is no meaningful default action for
-an empty rule; every empty rule must have an explicit action unless the
-rule's value does not matter.
address@hidden@code{$$ = $1}.}  Thus, the value of the first symbol in the rule
+becomes the value of the whole rule.  Of course, the default action is
+valid only if the two data types match.  There is no meaningful default
+action for an empty rule; every empty rule must have an explicit action
+unless the rule's value does not matter.
 
 @address@hidden with @var{n} zero or negative is allowed for reference
 to tokens and groupings on the stack @emph{before} those that match the
@@ -3174,6 +3176,7 @@
 * Precedence Decl::   Declaring terminals with precedence and associativity.
 * Union Decl::        Declaring the set of all semantic value types.
 * Type Decl::         Declaring the choice of type for a nonterminal symbol.
+* Destructor Decl::   Declaring how symbols are freed.
 * Expect Decl::       Suppressing warnings about shift/reduce conflicts.
 * Start Decl::        Specifying the start symbol.
 * Pure Decl::         Requesting a reentrant parser.
@@ -3364,6 +3367,72 @@
 terminal symbol.  All kinds of token declarations allow
 @code{<@var{type}>}.
 
address@hidden Destructor Decl
address@hidden Freeing Discarded Symbols
address@hidden freeing discarded symbols
address@hidden %destructor
+
+Some symbols can be discarded by the parser, typically during error
+recovery (@pxref{Error Recovery}).  Basically, during error recovery,
+embarrassing symbols already pushed on the stack, and embarrassing
+tokens coming from the rest of the file are thrown away until the parser
+falls on its feet.  If these symbols convey heap based information, this
+memory is lost.  While this behavior is tolerable for batch parsers,
+such as in compilers, it is unacceptable for parsers that can
+possibility ``never end'' such as shells, or implementations of
+communication protocols.
+
+The @code{%destructor} directive allows for the definition of code that
+is called when a symbol is thrown away.
+
address@hidden {Directive} %destructor @{ @var{code} @} @var{symbols}
address@hidden %destructor
+Declare that the @var{code} must be invoked for each of the
address@hidden that will be discarded by the parser.  The @var{code}
+should use @code{$$} to designate the semantic value associated to the
address@hidden  The additional parser parameters are also avaible
+(@pxref{Parser Function, , The Parser Function @code{yyparse}}).
+
address@hidden:} as of Bison 1.875, this feature is still considered as
+experimental, as there was not enough users feedback.  In particular,
+the syntax might still change, and for the time being, only the default
address@hidden(1) skeleton supports this feature.
address@hidden deffn
+
+For instance:
+
address@hidden
+%union
address@hidden
+  char *string;
address@hidden
+%token <string> STRING
+%type  <string> string
+%destructor @{ free ($$); @} STRING string
address@hidden smallexample
+
address@hidden
+guarantees that when a @code{STRING} or a @code{string} will be discarded,
+its associated memory will be freed.
+
+Note that in the future, Bison might also consider that right hand side
+members that are not mentioned in the action can be destroyed.  For
+instance, in:
+
address@hidden
+comment: "/*" STRING "*/";
address@hidden smallexample
+
address@hidden
+the parser is entitled to destroy the semantic value of the
address@hidden  Of course, this will not apply to the default action;
+compare:
+
address@hidden
+typeless: string;  // $$ = $1 does not apply; $1 is destroyed.
+typefull: string;  // $$ = $1 applies, $1 is not destroyed.
address@hidden smallexample
+
 @node Expect Decl
 @subsection Suppressing Conflict Warnings
 @cindex suppressing conflict warnings
@@ -3535,6 +3604,10 @@
 be able to refer to token type codes and the variable
 @code{yylval}.  @xref{Token Values, ,Semantic Values of Tokens}.
 
address@hidden %destructor
+Specifying how the parser should reclaim the memory associated to
+discarded symbols. @xref{Destructor Decl, , Freeing Discarded Symbols}.
+
 @item %file-prefix="@var{prefix}"
 Specify a prefix to use for all Bison output file names.  The names are
 chosen as if the input file were named @address@hidden
@@ -3634,8 +3707,6 @@
 that state.  @xref{Understanding, , Understanding Your Parser}, for more
 information.
 
-
-
 @item %yacc
 Pretend the option @option{--yacc} was given, i.e., imitate Yacc,
 including its naming conventions.  @xref{Bison Options}, for more.
@@ -5069,15 +5140,17 @@
 applicable in the ordinary way.
 
 But Bison can force the situation to fit the rule, by discarding part of
-the semantic context and part of the input.  First it discards states and
-objects from the stack until it gets back to a state in which the
+the semantic context and part of the input.  First it discards states
+and objects from the stack until it gets back to a state in which the
 @code{error} token is acceptable.  (This means that the subexpressions
-already parsed are discarded, back to the last complete @code{stmnts}.)  At
-this point the @code{error} token can be shifted.  Then, if the old
+already parsed are discarded, back to the last complete @code{stmnts}.)
+At this point the @code{error} token can be shifted.  Then, if the old
 look-ahead token is not acceptable to be shifted next, the parser reads
 tokens and discards them until it finds a token which is acceptable.  In
-this example, Bison reads and discards input until the next newline
-so that the fourth rule can apply.
+this example, Bison reads and discards input until the next newline so
+that the fourth rule can apply.  Note that discarded symbols are
+possible sources of memory leaks, see @ref{Destructor Decl, , Freeing
+Discarded Symbols}, for a means to reclaim this memory.
 
 The choice of error rules in the grammar is a choice of strategies for
 error recovery.  A simple and useful strategy is simply to skip the rest of
@@ -6302,6 +6375,10 @@
 Bison declaration to create a header file meant for the scanner.
 @xref{Decl Summary}.
 
address@hidden %destructor
+Specifying how the parser should reclaim the memory associated to
+discarded symbols. @xref{Destructor Decl, , Freeing Discarded Symbols}.
+
 @item %dprec
 Bison declaration to assign a precedence to a rule that is used at parse
 time to resolve reduce/reduce conflicts.  @xref{GLR Parsers, ,Writing
Index: 0.9/doc/version.texi
--- 0.9/doc/version.texi Sat, 09 Nov 2002 11:07:24 +0100 akim 
(bison/24_version.te 1.2 644)
+++ 0.9(w)/doc/version.texi Sun, 10 Nov 2002 11:23:23 +0100 akim 
(bison/24_version.te 1.2 644)
@@ -1,4 +1,4 @@
address@hidden UPDATED 9 November 2002
address@hidden UPDATED 10 November 2002
 @set UPDATED-MONTH November 2002
 @set EDITION 1.75b
 @set VERSION 1.75b
Index: 0.9/NEWS
--- 0.9/NEWS Fri, 08 Nov 2002 16:19:16 +0100 akim (bison/d/36_NEWS 1.1 644)
+++ 0.9(w)/NEWS Sun, 10 Nov 2002 12:52:33 +0100 akim (bison/d/36_NEWS 1.1 644)
@@ -3,6 +3,10 @@
 
 Changes in version 1.75b:
 
+* %destructor
+  It is now possible to reclaim the memory associated to symbols
+  discarded during error recovery.  This feature is still experimental.
+
 * Bison now parses C99 lexical constructs like digraphs, UCNs, and
   backslash-newline within C escape sequences, as POSIX now requires.
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]