Require default %destructor/%printer to be declared using

%symbol-default instead of an empty symbol list, and start working on
new per-type %destructor/%printer.  Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00007.html>.
* NEWS (2.3+): Add %symbol-default to example.
* bison.texinfo (Freeing Discarded Symbols): Likewise.
(Bison Symbols): Add entry for %symbol-default.
* src/parse-gram.y (PERCENT_SYMBOL_DEFAULT): New token.
(generic_symlist, generic_symlist_item): New nonterminals for creating
a list in which each item is a symbol, semantic type, or
%symbol-default.
(grammar_declaration): Use generic_symlist in %destructor and %printer
declarations instead of symbols.1 or an empty list.
(symbol_declaration, precedence_declaration, symbols.1): Update actions
for changes to symbol_list.
* src/reader.c: Update for changes to symbol_list.
* src/scan-code.l: Likewise.
* src/scan-gram.l: Scan new PERCENT_SYMBOL_DEFAULT token.
* src/symlist.c, src/symlist.h: Extend such that a list node may
represent a semantic type or a %symbol-default in addition to just an
ordinary symbol.  Add switched functions for setting %destructor's and
%printer's.
* tests/actions.at, tests/input.at: Add %symbol-default to all default
%destructor/%printer declarations.
This commit is contained in:
Joel E. Denny
2006-09-04 19:29:29 +00:00
parent 3508ce361b
commit 3be03b13e5
13 changed files with 821 additions and 651 deletions

View File

@@ -3986,6 +3986,7 @@ For instance, if your locations use a file name, you may use
@subsection Freeing Discarded Symbols
@cindex freeing discarded symbols
@findex %destructor
@findex %symbol-default
During error recovery (@pxref{Error Recovery}), symbols already pushed
on the stack and tokens coming from the rest of the file are discarded
@@ -4012,8 +4013,9 @@ The additional parser parameters are also available (@pxref{Parser Function, ,
The Parser Function @code{yyparse}}).
@end deffn
@deffn {Directive} %destructor @{ @var{code} @}
@deffn {Directive} %destructor @{ @var{code} @} %symbol-default
@cindex default %destructor
@findex %symbol-default
Invoke the braced @var{code} whenever the parser discards any user-defined
grammar symbol for which the user has not specifically declared any
@code{%destructor}.
@@ -4030,7 +4032,7 @@ For instance:
%token <string> STRING2
%type <string> string1
%type <string> string2
%destructor @{ free ($$); @}
%destructor @{ free ($$); @} %symbol-default
%destructor @{ free ($$); printf ("%d", @@$.first_line); @} STRING1 string1
@end smallexample
@@ -8505,6 +8507,11 @@ Bison declaration to specify the start symbol. @xref{Start Decl, ,The
Start-Symbol}.
@end deffn
@deffn {Directive} %symbol-default
Used to declare a default @code{%destructor} or default @code{%printer}.
@xref{Destructor Decl, , Freeing Discarded Symbols}.
@end deffn
@deffn {Directive} %token
Bison declaration to declare token(s) without specifying precedence.
@xref{Token Decl, ,Token Type Names}.