From 6557bcce8b9265a2a486f197beb613d86a1a0914 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 1 Apr 2012 13:15:41 +0200 Subject: [PATCH 01/22] c++: more YY_NULL Caught by maintainer-check-g++. * data/glr.c, data/lalr1.cc, data/yacc.c, tests/cxx-type.at, * tests/glr-regression.at, tests/push.at: When simple to do, avoid expliciting the null ptr. Otherwise use YY_NULL. (cherry picked from commit eeaf1dc646048e464d97f6a572b8894632e6e47a) Conflicts: data/glr.c data/lalr1.cc tests/cxx-type.at --- data/yacc.c | 20 ++--- tests/cxx-type.at | 166 ++++++++++++++++++++-------------------- tests/glr-regression.at | 2 +- tests/push.at | 10 +-- 4 files changed, 99 insertions(+), 99 deletions(-) diff --git a/data/yacc.c b/data/yacc.c index 284e13de..19fd3011 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -1245,12 +1245,12 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, ]b4_lac_if([[yytype_int16 *yyesa, yytype_int16 **yyes, YYSIZE_T *yyes_capacity, ]])[yytype_int16 *yyssp, int yytoken) { - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); YYSIZE_T yysize = yysize0; YYSIZE_T yysize1; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ - const char *yyformat = 0; + const char *yyformat = YY_NULL; /* Arguments of yyformat. */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Number of reported tokens (one for the "unexpected", one per @@ -1328,7 +1328,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, break; } yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) return 2; @@ -1417,7 +1417,7 @@ static char yypstate_allocated = 0;]])b4_pull_if([ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ { - return yypull_parse (0]m4_ifset([b4_parse_param], + return yypull_parse (YY_NULL]m4_ifset([b4_parse_param], [[, ]b4_c_args(b4_parse_param)])[); } @@ -1430,7 +1430,9 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ int yychar; YYSTYPE yylval;]b4_locations_if([[ YYLTYPE yylloc;]])])[ - if (yyps == 0) + if (yyps) + yyps_local = yyps; + else { yyps_local = yypstate_new (); if (!yyps_local) @@ -1441,14 +1443,12 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ return 2; } } - else - yyps_local = yyps; do { yychar = YYLEX; yystatus = yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])[); } while (yystatus == YYPUSH_MORE); - if (yyps == 0) + if (!yyps) yypstate_delete (yyps_local); return yystatus; }]])[ @@ -1458,10 +1458,10 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[ { yypstate *yyps;]b4_pure_if([], [[ if (yypstate_allocated) - return 0;]])[ + return YY_NULL;]])[ yyps = (yypstate *) malloc (sizeof *yyps); if (!yyps) - return 0; + return YY_NULL; yyps->yynew = 1;]b4_pure_if([], [[ yypstate_allocated = 1;]])[ return yyps; diff --git a/tests/cxx-type.at b/tests/cxx-type.at index 0c2b9605..746d05a4 100644 --- a/tests/cxx-type.at +++ b/tests/cxx-type.at @@ -92,35 +92,35 @@ $1 prog : | prog stmt { - char *output;]AT_LOCATION_IF([ - printf ("%d.%d-%d.%d: ", - @2.first_line, @2.first_column, - @2.last_line, @2.last_column);])[ - output = node_to_string (]$[2); - printf ("%s\n", output); - free (output); - free_node (]$[2); - } + char *output;]AT_LOCATION_IF([ + printf ("%d.%d-%d.%d: ", + @2.first_line, @2.first_column, + @2.last_line, @2.last_column);])[ + output = node_to_string (]$[2); + printf ("%s\n", output); + free (output); + free_node (]$[2); + } ; -stmt : expr ';' $2 { $$ = ]$[1; } +stmt : expr ';' $2 { $$ = ]$[1; } | decl $3 - | error ';' { $$ = new_nterm ("", 0, 0, 0); } - | '@' { YYACCEPT; } + | error ';' { $$ = new_nterm ("", YY_NULL, YY_NULL, YY_NULL); } + | '@' { YYACCEPT; } ; expr : ID | TYPENAME '(' expr ')' - { $$ = new_nterm ("(%s,%s)", ]$[3, ]$[1, 0); } - | expr '+' expr { $$ = new_nterm ("+(%s,%s)", ]$[1, ]$[3, 0); } - | expr '=' expr { $$ = new_nterm ("=(%s,%s)", ]$[1, ]$[3, 0); } + { $$ = new_nterm ("(%s,%s)", ]$[3, ]$[1, YY_NULL); } + | expr '+' expr { $$ = new_nterm ("+(%s,%s)", ]$[1, ]$[3, YY_NULL); } + | expr '=' expr { $$ = new_nterm ("=(%s,%s)", ]$[1, ]$[3, YY_NULL); } ; decl : TYPENAME declarator ';' - { $$ = new_nterm ("(%s,%s)", ]$[1, ]$[2, 0); } + { $$ = new_nterm ("(%s,%s)", ]$[1, ]$[2, YY_NULL); } | TYPENAME declarator '=' expr ';' - { $$ = new_nterm ("(%s,%s,%s)", ]$[1, - ]$[2, ]$[4); } + { $$ = new_nterm ("(%s,%s,%s)", ]$[1, + ]$[2, ]$[4); } ; declarator : ID @@ -163,60 +163,60 @@ yylex (LEX_PARAMETERS) while (1) { if (feof (stdin)) - abort (); + abort (); c = getchar (); switch (c) - { - case EOF: - return 0; - case '\t': - colNum = (colNum + 7) & ~7; - break; - case ' ': case '\f': - colNum += 1; - break; - case '\n': - lineNum += 1; - colNum = 0; - break; - default: - { - int tok; + { + case EOF: + return 0; + case '\t': + colNum = (colNum + 7) & ~7; + break; + case ' ': case '\f': + colNum += 1; + break; + case '\n': + lineNum += 1; + colNum = 0; + break; + default: + { + int tok; #if YYLSP_NEEDED - yylloc.first_line = yylloc.last_line = lineNum; - yylloc.first_column = colNum; + yylloc.first_line = yylloc.last_line = lineNum; + yylloc.first_column = colNum; #endif - if (isalpha (c)) - { - i = 0; + if (isalpha (c)) + { + i = 0; - do - { - buffer[i++] = c; - colNum += 1; - if (i == sizeof buffer - 1) - abort (); - c = getchar (); - } - while (isalnum (c) || c == '_'); + do + { + buffer[i++] = c; + colNum += 1; + if (i == sizeof buffer - 1) + abort (); + c = getchar (); + } + while (isalnum (c) || c == '_'); - ungetc (c, stdin); - buffer[i++] = 0; - tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID; - yylval = new_term (strcpy ((char *) malloc (i), buffer)); - } - else - { - colNum += 1; - tok = c; - yylval = 0; - } + ungetc (c, stdin); + buffer[i++] = 0; + tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID; + yylval = new_term (strcpy ((char *) malloc (i), buffer)); + } + else + { + colNum += 1; + tok = c; + yylval = YY_NULL; + } #if YYLSP_NEEDED - yylloc.last_column = colNum-1; + yylloc.last_column = colNum-1; #endif - return tok; - } - } + return tok; + } + } } } @@ -298,7 +298,7 @@ node_to_string (Node *node) child1 = node_to_string (node->nterm.children[1]); child2 = node_to_string (node->nterm.children[2]); buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0) - + strlen (child1) + strlen (child2) + 1); + + strlen (child1) + strlen (child2) + 1); sprintf (buffer, node->nterm.form, child0, child1, child2); free (child0); free (child1); @@ -314,7 +314,7 @@ m4_bmatch([$2], [stmtMerge], [[static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1) { - return new_nterm ("(%s,%s)", x0, x1, 0); + return new_nterm ("(%s,%s)", x0, x1, YY_NULL); } ]]) ) @@ -412,61 +412,61 @@ m4_define([_AT_VERBOSE_GLR_STDERR], AT_SETUP([GLR: Resolve ambiguity, impure, no locations]) _AT_TEST_GLR_CXXTYPES([], - [%dprec 1], [%dprec 2]) + [%dprec 1], [%dprec 2]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, impure, locations]) _AT_TEST_GLR_CXXTYPES([%locations],[%dprec 1],[%dprec 2]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_RESOLVED_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR) + _AT_RESOLVED_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, pure, no locations]) _AT_TEST_GLR_CXXTYPES([%define api.pure], - [%dprec 1], [%dprec 2]) + [%dprec 1], [%dprec 2]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) + _AT_RESOLVED_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Resolve ambiguity, pure, locations]) _AT_TEST_GLR_CXXTYPES([%define api.pure %locations], - [%dprec 1], [%dprec 2]) + [%dprec 1], [%dprec 2]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_RESOLVED_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR) + _AT_RESOLVED_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, impure, no locations]) _AT_TEST_GLR_CXXTYPES([], - [%merge ], [%merge ]) + [%merge ], [%merge ]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, impure, locations]) _AT_TEST_GLR_CXXTYPES([%locations], - [%merge ], [%merge ]) + [%merge ], [%merge ]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_AMBIG_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, pure, no locations]) _AT_TEST_GLR_CXXTYPES([%define api.pure], - [%merge ], [%merge ]) + [%merge ], [%merge ]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Merge conflicting parses, pure, locations]) _AT_TEST_GLR_CXXTYPES([%define api.pure %locations], - [%merge ],[%merge ]) + [%merge ],[%merge ]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_AMBIG_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT_WITH_LOC, _AT_GLR_STDERR) AT_CLEANUP AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations]) _AT_TEST_GLR_CXXTYPES([%error-verbose], - [%merge ], [%merge ]) + [%merge ], [%merge ]) AT_PARSER_CHECK([[./types test-input]], 0, - _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR) + _AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR) AT_CLEANUP diff --git a/tests/glr-regression.at b/tests/glr-regression.at index d1d0b878..0cbffd19 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -298,7 +298,7 @@ static void yyerror(char const * s) { fprintf(stderr,"error: %s\n",s); } -FILE *input = NULL; +FILE *input = YY_NULL; int P[] = { P1, P2 }; int O[] = { O1, O2 }; diff --git a/tests/push.at b/tests/push.at index adb51358..21322f0d 100644 --- a/tests/push.at +++ b/tests/push.at @@ -60,12 +60,12 @@ main (void) /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the parse did not return on success, syntax error, or memory exhaustion. */ ps = yypstate_new (); - assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE); + assert (yypush_parse (ps, 'a', YY_NULL) == YYPUSH_MORE); yypstate_delete (ps); ps = yypstate_new (); - assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE); - assert (yypush_parse (ps, 'b', NULL) == YYPUSH_MORE); + assert (yypush_parse (ps, 'a', YY_NULL) == YYPUSH_MORE); + assert (yypush_parse (ps, 'b', YY_NULL) == YYPUSH_MORE); yypstate_delete (ps); return 0; @@ -124,11 +124,11 @@ main (void) { ps = yypstate_new (); assert (ps); - assert (yypstate_new () == NULL); + assert (yypstate_new () == YY_NULL); ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[; yychar = 0; assert (yypush_parse (ps) == 0); - assert (yypstate_new () == NULL); + assert (yypstate_new () == YY_NULL); ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[; yypstate_delete (ps); } From 4a11b8524992872c28f02d67cc4188c366f2b4bc Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 2 Apr 2012 16:43:26 +0200 Subject: [PATCH 02/22] doc: fix documentation of YYERROR. * doc/bison.texinfo (Table of Symbols): Fix the documentation of YYERROR by copying that from "Action Features". --- doc/bison.texinfo | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 76a7dbae..3212be91 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -9933,7 +9933,7 @@ Return immediately from the parser, indicating success. @end deffn @deffn {Statement} {return YYERROR;} -Start error recovery without printing an error message. +Start error recovery (without printing an error message). @xref{Error Recovery}. @end deffn @@ -10911,10 +10911,11 @@ after a syntax error. @xref{Error Recovery}. @end deffn @deffn {Macro} YYERROR -Macro to pretend that a syntax error has just been detected: call -@code{yyerror} and then perform normal error recovery if possible -(@pxref{Error Recovery}), or (if recovery is impossible) make -@code{yyparse} return 1. @xref{Error Recovery}. +Cause an immediate syntax error. This statement initiates error +recovery just as if the parser itself had detected an error; however, it +does not call @code{yyerror}, and does not print any message. If you +want to print an error message, call @code{yyerror} explicitly before +the @samp{YYERROR;} statement. @xref{Error Recovery}. For Java parsers, this functionality is invoked using @code{return YYERROR;} instead. From 34a41a93c7801129370dc4133db310e40ee748c5 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 3 Apr 2012 13:15:20 +0200 Subject: [PATCH 03/22] doc: fix index. http://lists.gnu.org/archive/html/bison-patches/2012-04/msg00006.html * doc/bison.texinfo: Avoid using @def* variant with more than the defined entity as main entity, as it results in an incorrect index. For instance, don't document {return YYERROR;}, which results in a single index entry "return YYERROR;", but rather as typed function whose return type is "type", and whose argument list is ";". --- doc/bison.texinfo | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 3212be91..86809c11 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -5659,7 +5659,7 @@ This function is available if either the @code{%define api.push-pull push} or @code{%define api.push-pull both} declaration is used. @xref{Push Decl, ,A Push Parser}. -@deftypefun yypstate *yypstate_new (void) +@deftypefun {yypstate*} yypstate_new (void) The function will return a valid parser instance if there was memory available or 0 if no memory was available. In impure mode, it will also return 0 if a parser instance is currently @@ -6081,17 +6081,17 @@ union specified by the @code{%union} declaration. @xref{Action Types, ,Data Types of Values in Actions}. @end deffn -@deffn {Macro} YYABORT; +@deffn {Macro} YYABORT @code{;} Return immediately from @code{yyparse}, indicating failure. @xref{Parser Function, ,The Parser Function @code{yyparse}}. @end deffn -@deffn {Macro} YYACCEPT; +@deffn {Macro} YYACCEPT @code{;} Return immediately from @code{yyparse}, indicating success. @xref{Parser Function, ,The Parser Function @code{yyparse}}. @end deffn -@deffn {Macro} YYBACKUP (@var{token}, @var{value}); +@deffn {Macro} YYBACKUP (@var{token}, @var{value})@code{;} @findex YYBACKUP Unshift a token. This macro is allowed only for rules that reduce a single value, and only when there is no lookahead token. @@ -6109,18 +6109,15 @@ In either case, the rest of the action is not executed. @end deffn @deffn {Macro} YYEMPTY -@vindex YYEMPTY Value stored in @code{yychar} when there is no lookahead token. @end deffn @deffn {Macro} YYEOF -@vindex YYEOF Value stored in @code{yychar} when the lookahead is the end of the input stream. @end deffn -@deffn {Macro} YYERROR; -@findex YYERROR +@deffn {Macro} YYERROR @code{;} Cause an immediate syntax error. This statement initiates error recovery just as if the parser itself had detected an error; however, it does not call @code{yyerror}, and does not print any message. If you @@ -6144,7 +6141,7 @@ Actions}). @xref{Lookahead, ,Lookahead Tokens}. @end deffn -@deffn {Macro} yyclearin; +@deffn {Macro} yyclearin @code{;} Discard the current lookahead token. This is useful primarily in error rules. Do not invoke @code{yyclearin} in a deferred semantic action (@pxref{GLR @@ -6152,7 +6149,7 @@ Semantic Actions}). @xref{Error Recovery}. @end deffn -@deffn {Macro} yyerrok; +@deffn {Macro} yyerrok @code{;} Resume generating error messages immediately for subsequent syntax errors. This is useful primarily in error rules. @xref{Error Recovery}. @@ -9922,20 +9919,20 @@ The location information of the grouping made by the current rule. @xref{Java Location Values}. @end defvar -@deffn {Statement} {return YYABORT;} +@deftypefn {Statement} return YYABORT @code{;} Return immediately from the parser, indicating failure. @xref{Java Parser Interface}. -@end deffn +@end deftypefn -@deffn {Statement} {return YYACCEPT;} +@deftypefn {Statement} return YYACCEPT @code{;} Return immediately from the parser, indicating success. @xref{Java Parser Interface}. -@end deffn +@end deftypefn -@deffn {Statement} {return YYERROR;} +@deftypefn {Statement} {return} YYERROR @code{;} Start error recovery (without printing an error message). @xref{Error Recovery}. -@end deffn +@end deftypefn @deftypefn {Function} {boolean} recovering () Return whether error recovery is being done. In this state, the parser From 466b4cf2017646239984467733e63a2cfb98fd8f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 4 Apr 2012 10:09:30 +0200 Subject: [PATCH 04/22] maint: update NEWS. * NEWS: Fix entry about __attribute__. Reorder by "decreasing" order of importance. --- NEWS | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index f552c323..544478af 100644 --- a/NEWS +++ b/NEWS @@ -3,28 +3,14 @@ Bison News * Changes in version 2.5.1 (????-??-??): -** Several portability problems in the test suite have been fixed: - - This includes warnings with some compilers, unexpected behavior of - tools such as diff, warning messages from the test suite itself, - etc. +** glr.c: __attribute__ is preserved: __attribute__ is not longer disabled when __STRICT_ANSI__ is defined (i.e., when -std is passed to GCC). -** Warnings during the build procedure have been eliminated. +** yacc.c: YYBACKUP works as expected. -** Many minor improvements have been made to the manual: - - The layout for grammar has changed to a more compact scheme. Named - references are motivated. The description of the automaton - description file is updated. - -** YYBACKUP works as expected. - -** liby is no longer asking for "rpl_fprintf" on some platforms. - -** Several Java fixes: +** lalr1.java: several fixes: The Java parser no longer throws ArrayIndexOutOfBoundsException if the first token leads to a syntax error. Some minor clean ups. @@ -40,6 +26,24 @@ Bison News methods) accept new arguments for line and column. Several issues in the documentation were fixed. +** liby is no longer asking for "rpl_fprintf" on some platforms. + +** Several improvements have been made to the manual: + + The layout for grammar excerpts was changed to a more compact + scheme. Named references are motivated. The description of the + automaton description file (*.output) is updated to the current + format. Incorrect index entries were fixed. Some other errors were + fixed. + +** Warnings during the build procedure have been eliminated. + +** Several portability problems in the test suite have been fixed: + + This includes warnings with some compilers, unexpected behavior of + tools such as diff, warning messages from the test suite itself, + etc. + * Changes in version 2.5 (2011-05-14): ** Grammar symbol names can now contain non-initial dashes: From 163bb3698ff43cfc88947758701250e23deffca5 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 7 Apr 2012 13:51:20 +0200 Subject: [PATCH 05/22] gnulib: update. * bootstrap.conf (bootstrap_sync): True again. It was disabled while waiting for changes to be integrated in gnulib's bootstrap, which was done long ago. * bootstrap, gnulib: Update. --- bootstrap | 11 ++++++----- bootstrap.conf | 2 +- gnulib | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bootstrap b/bootstrap index edac17e0..31eb651f 100755 --- a/bootstrap +++ b/bootstrap @@ -1,6 +1,6 @@ #! /bin/sh # Print a version string. -scriptversion=2012-01-23.10; # UTC +scriptversion=2012-02-11.09; # UTC # Bootstrap this package from checked-out sources. @@ -137,7 +137,7 @@ tests_base=tests gnulib_extra_files='' # Additional gnulib-tool options to use. Use "\newline" to break lines. -gnulib_tool_option_extras='--makefile-name=gnulib.mk' +gnulib_tool_option_extras= # Other locale categories that need message catalogs. EXTRA_LOCALE_CATEGORIES= @@ -423,7 +423,7 @@ check_versions() { $use_git || continue fi # Honor $APP variables ($TAR, $AUTOCONF, etc.) - appvar=`echo $app | tr '[a-z]-' '[A-Z]_'` + appvar=`echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_'` test "$appvar" = TAR && appvar=AMTAR case $appvar in GZIP) ;; # Do not use $GZIP: it contains gzip options. @@ -604,7 +604,7 @@ if $bootstrap_sync; then fi gnulib_tool=$GNULIB_SRCDIR/gnulib-tool -<$gnulib_tool || exit +<$gnulib_tool || exit $? # Get translations. @@ -807,7 +807,8 @@ for file in $gnulib_files; do symlink_to_dir "$GNULIB_SRCDIR" $file || exit done -bootstrap_post_import_hook +bootstrap_post_import_hook \ + || { echo >&2 "$me: bootstrap_post_import_hook failed"; exit 1; } # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some # gnulib-populated directories. Such .m4 files would cause aclocal to fail. diff --git a/bootstrap.conf b/bootstrap.conf index e9b8ba6c..2dbcb057 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -82,4 +82,4 @@ bootstrap_epilogue() # the bootstrap entry from the file .x-update-copyright, and add any # needed copyright years to the copyright statement in the bootstrap # script. -# FIXME: temporary bootstrap_sync=true +bootstrap_sync=true diff --git a/gnulib b/gnulib index 0e9d9267..55cc8db0 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 0e9d9267fa36c5493b36c0a2b2e422da101ee4b4 +Subproject commit 55cc8db041f845c2e82ed10aa192ac200ab3f530 From ff1b7a13334749a40ad51b37db1aa49a2cc6bc86 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 9 Apr 2012 15:00:12 +0200 Subject: [PATCH 06/22] TODO: import from master. * TODO: Copy the current version. --- TODO | 244 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 182 insertions(+), 62 deletions(-) diff --git a/TODO b/TODO index 5807ccdc..13c1f858 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,133 @@ --*- outline -*- +* Short term +** Variable names. +What should we name `variant' and `lex_symbol'? + +** Use b4_symbol in all the skeleton +Move its definition in the more standard places and deploy it in other +skeletons. Then remove the older system, including the tables +generated by output.c + +** Update the documentation on gnu.org + +** Get rid of fake #lines [Bison: ...] +Possibly as simple as checking whether the column number is nonnegative. + +I have seen messages like the following from GCC. + +:0: fatal error: opening dependency file .deps/libltdl/argz.Tpo: No such file or directory + + +** Discuss about %printer/%destroy in the case of C++. +It would be very nice to provide the symbol classes with an operator<< +and a destructor. Unfortunately the syntax we have chosen for +%destroy and %printer make them hard to reuse. For instance, the user +is invited to write something like + + %printer { debug_stream() << $$; } ; + +which is hard to reuse elsewhere since it wants to use +"debug_stream()" to find the stream to use. The same applies to +%destroy: we told the user she could use the members of the Parser +class in the printers/destructors, which is not good for an operator<< +since it is no longer bound to a particular parser, it's just a +(standalone symbol). + +** Rename LR0.cc +as lr0.cc, why upper case? + +** bench several bisons. +Enhance bench.pl with %b to run different bisons. + +* Various +** Warnings +Warnings about type tags that are used in printer and dtors, but not +for symbols? + +** YYERRCODE +Defined to 256, but not used, not documented. Probably the token +number for the error token, which POSIX wants to be 256, but which +Bison might renumber if the user used number 256. Keep fix and doc? +Throw away? + +Also, why don't we output the token name of the error token in the +output? It is explicitly skipped: + + /* Skip error token and tokens without identifier. */ + if (sym != errtoken && id) + +Of course there are issues with name spaces, but if we disable we have +something which seems to be more simpler and more consistent instead +of the special case YYERRCODE. + + enum yytokentype { + error = 256, + // ... + }; + + +We could (should?) also treat the case of the undef_token, which is +numbered 257 for yylex, and 2 internal. Both appear for instance in +toknum: + + const unsigned short int + parser::yytoken_number_[] = + { + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + +while here + + enum yytokentype { + TOK_EOF = 0, + TOK_EQ = 258, + +so both 256 and 257 are "mysterious". + + const char* + const parser::yytname_[] = + { + "\"end of command\"", "error", "$undefined", "\"=\"", "\"break\"", + + +** YYFAIL +It is seems to be *really* obsolete now, shall we remove it? + +** yychar == yyempty_ +The code in yyerrlab reads: + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + +There are only two yychar that can be <= YYEOF: YYEMPTY and YYEOF. +But I can't produce the situation where yychar is YYEMPTY here, is it +really possible? The test suite does not exercise this case. + +This shows that it would be interesting to manage to install skeleton +coverage analysis to the test suite. + +** Table definitions +It should be very easy to factor the definition of the various tables, +including the separation bw declaration and definition. See for +instance b4_table_define in lalr1.cc. This way, we could even factor +C vs. C++ definitions. + +* From lalr1.cc to yacc.c +** Single stack +Merging the three stacks in lalr1.cc simplified the code, prompted for +other improvements and also made it faster (probably because memory +management is performed once instead of three times). I suggest that +we do the same in yacc.c. + +** yysyntax_error +The code bw glr.c and yacc.c is really alike, we can certainly factor +some parts. * Header guards -From Franc,ois: should we keep the directory part in the CPP guard? +From François: should we keep the directory part in the CPP guard? * Yacc.c: CPP Macros @@ -12,18 +137,19 @@ They should not: it is not documented. But if they need to, let's find something clean (not like YYLSP_NEEDED...). -* Installation - * Documentation Before releasing, make sure the documentation ("Understanding your parser") refers to the current `output' format. -* lalr1.cc -** vector -Move to using vector, drop stack.hh. - * Report +** Figures +Some statistics about the grammar and the parser would be useful, +especially when asking the user to send some information about the +grammars she is working on. We should probably also include some +information about the variables (I'm not sure for instance we even +specify what LR variant was used). + ** GLR How would Paul like to display the conflicted actions? In particular, what when two reductions are possible on a given lookahead token, but one is @@ -56,7 +182,7 @@ DeRemer and Penello: they already provide the algorithm. We should find a means to provide an access to values deep in the stack. For instance, instead of - baz: qux { $$ = $-1 + $0 + $1; } + baz: qux { $$ = $-1 + $0 + $1; } we should be able to have: @@ -71,9 +197,6 @@ must be in the scanner: we must not parse what is in a switched off part of %if. Akim Demaille thinks it should be in the parser, so as to avoid falling into another CPP mistake. -** -D, --define-muscle NAME=VALUE -To define muscles via cli. Or maybe support directly NAME=VALUE? - ** XML Output There are couple of available extensions of Bison targeting some XML output. Some day we should consider including them. One issue is @@ -92,13 +215,13 @@ XML output for GNU Bison * Unit rules Maybe we could expand unit rules, i.e., transform - exp: arith | bool; - arith: exp '+' exp; - bool: exp '&' exp; + exp: arith | bool; + arith: exp '+' exp; + bool: exp '&' exp; into - exp: exp '+' exp | exp '&' exp; + exp: exp '+' exp | exp '&' exp; when there are no actions. This can significantly speed up some grammars. I can't find the papers. In particular the book `LR @@ -114,7 +237,8 @@ this issue. Does anybody have it? Some history of Bison and some bibliography would be most welcome. Are there any Texinfo standards for bibliography? - +** %printer +Wow, %printer is not documented. Clearly mark YYPRINT as obsolete. * Java, Fortran, etc. @@ -122,19 +246,19 @@ Are there any Texinfo standards for bibliography? * Coding system independence Paul notes: - Currently Bison assumes 8-bit bytes (i.e. that UCHAR_MAX is - 255). It also assumes that the 8-bit character encoding is - the same for the invocation of 'bison' as it is for the - invocation of 'cc', but this is not necessarily true when - people run bison on an ASCII host and then use cc on an EBCDIC - host. I don't think these topics are worth our time - addressing (unless we find a gung-ho volunteer for EBCDIC or - PDP-10 ports :-) but they should probably be documented - somewhere. + Currently Bison assumes 8-bit bytes (i.e. that UCHAR_MAX is + 255). It also assumes that the 8-bit character encoding is + the same for the invocation of 'bison' as it is for the + invocation of 'cc', but this is not necessarily true when + people run bison on an ASCII host and then use cc on an EBCDIC + host. I don't think these topics are worth our time + addressing (unless we find a gung-ho volunteer for EBCDIC or + PDP-10 ports :-) but they should probably be documented + somewhere. - More importantly, Bison does not currently allow NUL bytes in - tokens, either via escapes (e.g., "x\0y") or via a NUL byte in - the source code. This should get fixed. + More importantly, Bison does not currently allow NUL bytes in + tokens, either via escapes (e.g., "x\0y") or via a NUL byte in + the source code. This should get fixed. * --graph Show reductions. @@ -144,15 +268,14 @@ Show reductions. ** Skeleton strategy Must we keep %token-table? -* src/print_graph.c -Find the best graph parameters. - * BTYacc See if we can integrate backtracking in Bison. Charles-Henri de -Boysson is working on this, and already has some -results. Vadim Maslow, the maintainer of BTYacc was contacted, and we -stay in touch with him. Adjusting the Bison grammar parser will be -needed to support some extra BTYacc features. This is less urgent. +Boysson has been working on this, but never gave +the results. + +Vadim Maslow, the maintainer of BTYacc was once contacted. Adjusting +the Bison grammar parser will be needed to support some extra BTYacc +features. This is less urgent. ** Keeping the conflicted actions First, analyze the differences between byacc and btyacc (I'm referring @@ -167,9 +290,6 @@ very feasible to use the very same conflict tables. ** Adjust the skeletons Import the skeletons for C and C++. -** Improve the skeletons -Have them support yysymprint, yydestruct and so forth. - * Precedence @@ -178,15 +298,6 @@ It is unfortunate that there is a total order for precedence. It makes it impossible to have modular precedence information. We should move to partial orders (sounds like series/parallel orders to me). -** Correlation b/w precedence and associativity -Also, I fail to understand why we have to assign the same -associativity to operators with the same precedence. For instance, -why can't I decide that the precedence of * and / is the same, but the -latter is nonassoc? - -If there is really no profound motivation, we should find a new syntax -to allow specifying this. - ** RR conflicts See if we can use precedence between rules to solve RR conflicts. See what POSIX says. @@ -215,20 +326,6 @@ $$ = $1. I therefore think that one should implement a Bison option where every typed default rule is explicitly written out (same typed ruled can of course be grouped together). -Note: Robert Anisko handles this. He knows how to do it. - - -* Warnings -It would be nice to have warning support. See how Autoconf handles -them, it is fairly well described there. It would be very nice to -implement this in such a way that other programs could use -lib/warnings.[ch]. - -Don't work on this without first announcing you do, as I already have -thought about it, and know many of the components that can be used to -implement it. - - * Pre and post actions. From: Florian Krohm Subject: YYACT_EPILOGUE @@ -260,6 +357,29 @@ to bison. If you're interested, I'll work on a patch. * Better graphics Equip the parser with a means to create the (visual) parse tree. +* Complaint submessage indentation. +We already have an implementation that works fairly well for named +reference messages, but it would be nice to use it consistently for all +submessages from Bison. For example, the "previous definition" +submessage or the list of correct values for a %define variable might +look better with indentation. + +However, the current implementation makes the assumption that the +location printed on the first line is not usually much shorter than the +locations printed on the submessage lines that follow. That assumption +may not hold true as often for some kinds of submessages especially if +we ever support multiple grammar files. + +Here's a proposal for how a new implementation might look: + + http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00086.html + + +Local Variables: +mode: outline +coding: utf-8 +End: + ----- Copyright (C) 2001-2004, 2006, 2008-2012 Free Software Foundation, Inc. From 7beac808142d10724e16d623ce5d56f530449ade Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 9 Apr 2012 15:03:21 +0200 Subject: [PATCH 07/22] TODO: remove dead items. * TODO (Documentation, %printer, Java): Remove, already done (or just waiting for approval). (Fortran, BTYacc): Remove, there does not seem to be demand. --- TODO | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/TODO b/TODO index 13c1f858..d86d8d8b 100644 --- a/TODO +++ b/TODO @@ -136,11 +136,6 @@ Do some people use YYPURE, YYLSP_NEEDED like we do in the test suite? They should not: it is not documented. But if they need to, let's find something clean (not like YYLSP_NEEDED...). - -* Documentation -Before releasing, make sure the documentation ("Understanding your -parser") refers to the current `output' format. - * Report ** Figures @@ -237,12 +232,6 @@ this issue. Does anybody have it? Some history of Bison and some bibliography would be most welcome. Are there any Texinfo standards for bibliography? -** %printer -Wow, %printer is not documented. Clearly mark YYPRINT as obsolete. - -* Java, Fortran, etc. - - * Coding system independence Paul notes: @@ -268,29 +257,6 @@ Show reductions. ** Skeleton strategy Must we keep %token-table? -* BTYacc -See if we can integrate backtracking in Bison. Charles-Henri de -Boysson has been working on this, but never gave -the results. - -Vadim Maslow, the maintainer of BTYacc was once contacted. Adjusting -the Bison grammar parser will be needed to support some extra BTYacc -features. This is less urgent. - -** Keeping the conflicted actions -First, analyze the differences between byacc and btyacc (I'm referring -to the executables). Find where the conflicts are preserved. - -** Compare with the GLR tables -See how isomorphic the way BTYacc and the way the GLR adjustments in -Bison are compatible. *As much as possible* one should try to use the -same implementation in the Bison executables. I insist: it should be -very feasible to use the very same conflict tables. - -** Adjust the skeletons -Import the skeletons for C and C++. - - * Precedence ** Partial order From debe2c03c469e8b495d138b81135fba985ac2efb Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 10 Apr 2012 08:07:17 +0200 Subject: [PATCH 08/22] NEWS: 2.6 will drop K&R. * NEWS: here. (glr.c): Fix a spello. --- NEWS | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 544478af..52b20457 100644 --- a/NEWS +++ b/NEWS @@ -3,13 +3,17 @@ Bison News * Changes in version 2.5.1 (????-??-??): -** glr.c: __attribute__ is preserved: +** Future changes: - __attribute__ is not longer disabled when __STRICT_ANSI__ is defined - (i.e., when -std is passed to GCC). + The next major release will drop support for K&R C. ** yacc.c: YYBACKUP works as expected. +** glr.c: __attribute__ is preserved: + + __attribute__ is no longer disabled when __STRICT_ANSI__ is defined + (i.e., when -std is passed to GCC). + ** lalr1.java: several fixes: The Java parser no longer throws ArrayIndexOutOfBoundsException if From d834eca014bd545fb359d20687b4ce2c6875219d Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 10 Apr 2012 08:07:32 +0200 Subject: [PATCH 09/22] glr: eliminate last bits of unwanted locations. * data/glr.c (YYLTYPE): Do not define when locations are not demanded. Adjust all dependencies. --- NEWS | 9 ++++++++- data/glr.c | 29 ++++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/NEWS b/NEWS index 52b20457..b49f2c84 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,14 @@ Bison News ** yacc.c: YYBACKUP works as expected. -** glr.c: __attribute__ is preserved: +** glr.c improvements: + +*** Location support is eliminated when not requested: + + GLR parsers used to include location-related code even when + locations were not requested, and therefore not even usable. + +*** __attribute__ is preserved: __attribute__ is no longer disabled when __STRICT_ANSI__ is defined (i.e., when -std is passed to GCC). diff --git a/data/glr.c b/data/glr.c index d0b26926..0e62c6ac 100644 --- a/data/glr.c +++ b/data/glr.c @@ -207,23 +207,19 @@ b4_token_enums(b4_tokens) [[typedef int YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1]])])[ #endif - +]b4_locations_if([[ #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED typedef struct YYLTYPE { -]b4_locations_if([ int first_line; int first_column; int last_line; int last_column; -],[ - char yydummy; -])[ } YYLTYPE; # define YYLTYPE_IS_DECLARED 1 # define YYLTYPE_IS_TRIVIAL 1 #endif - +]])[ ]b4_percent_code_get([[provides]])[]dnl ]) @@ -566,9 +562,8 @@ m4_if(b4_prefix[], [yy], [], #define b4_prefix[]char yychar #define b4_prefix[]lval yylval #define b4_prefix[]lloc yylloc])], -[YYSTYPE yylval; - -YYLTYPE yylloc; +[YYSTYPE yylval;]b4_locations_if([[ +YYLTYPE yylloc;]])[ int yynerrs; int yychar;])[ @@ -774,9 +769,9 @@ struct yyGLRState { yySemanticOption* yyfirstVal; /** Semantic value for this state. */ YYSTYPE yysval; - } yysemantics; + } yysemantics;]b4_locations_if([[ /** Source location for this state. */ - YYLTYPE yyloc; + YYLTYPE yyloc;]])[ }; struct yyGLRStateSet { @@ -798,8 +793,8 @@ struct yySemanticOption { yyGLRState* yystate; /** The lookahead for this reduction. */ int yyrawchar; - YYSTYPE yyval; - YYLTYPE yyloc; + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ /** Next sibling in chain of options. To facilitate merging, * options are chained in decreasing order by address. */ yySemanticOption* yynext; @@ -820,8 +815,8 @@ struct yyGLRStack { [ int yyerrcnt; int yyrawchar; - YYSTYPE yyval; - YYLTYPE yyloc; + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ ])[ YYJMP_BUF yyexception_buffer; yyGLRStackItem* yyitems; @@ -880,8 +875,8 @@ yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) { YYASSERT (s->yyresolved); yyvsp[i].yystate.yyresolved = yytrue; - yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval; - yyvsp[i].yystate.yyloc = s->yyloc; + yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;]b4_locations_if([[ + yyvsp[i].yystate.yyloc = s->yyloc;]])[ s = yyvsp[i].yystate.yypred = s->yypred; } } From 3d05bae83a2b47b06fdaff9d26495d68e181622d Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 10 Apr 2012 20:49:47 +0200 Subject: [PATCH 10/22] build: autoconf: update. * submodules/autoconf: Update. There are no changes in data/m4sugar/foreach.m4, and the changes in data/m4sugar/m4sugar.m4 are minor. --- submodules/autoconf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/autoconf b/submodules/autoconf index f4be358c..0db9c1a1 160000 --- a/submodules/autoconf +++ b/submodules/autoconf @@ -1 +1 @@ -Subproject commit f4be358c2b97736cda5a0d543fa3d34d3cde40bd +Subproject commit 0db9c1a19fbbdbf8728ec8d9c5a020d070ec23b2 From 22cd137bc99f9368a5e3087cef701f8d74d8fd71 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 10 Apr 2012 20:58:20 +0200 Subject: [PATCH 11/22] build: flex.m4. * m4/flex.m4: New. An exact copy of what is in Autoconf currently. --- m4/flex.m4 | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 m4/flex.m4 diff --git a/m4/flex.m4 b/m4/flex.m4 new file mode 100644 index 00000000..3327bf9b --- /dev/null +++ b/m4/flex.m4 @@ -0,0 +1,93 @@ +# flex.m4 serial 1 +# Copyright (C) 2012 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AC_PROG_LEX +# ----------- +# Look for flex or lex. Set its associated library to LEXLIB. +# Check if lex declares yytext as a char * by default, not a char[]. +AN_MAKEVAR([LEX], [AC_PROG_LEX]) +AN_PROGRAM([lex], [AC_PROG_LEX]) +AN_PROGRAM([flex], [AC_PROG_LEX]) +AC_DEFUN_ONCE([AC_PROG_LEX], +[AC_CHECK_PROGS(LEX, flex lex, :) +if test "x$LEX" != "x:"; then + _AC_PROG_LEX_YYTEXT_DECL +fi]) + + +# _AC_PROG_LEX_YYTEXT_DECL +# ------------------------ +# Check for the Lex output root, the Lex library, and whether Lex +# declares yytext as a char * by default. +m4_define([_AC_PROG_LEX_YYTEXT_DECL], +[cat >conftest.l <<_ACEOF[ +%% +a { ECHO; } +b { REJECT; } +c { yymore (); } +d { yyless (1); } +e { /* IRIX 6.5 flex 2.5.4 underquotes its yyless argument. */ + yyless ((input () != 0)); } +f { unput (yytext[0]); } +. { BEGIN INITIAL; } +%% +#ifdef YYTEXT_POINTER +extern char *yytext; +#endif +int +main (void) +{ + return ! yylex () + ! yywrap (); +} +]_ACEOF +_AC_DO_VAR(LEX conftest.l) +AC_CACHE_CHECK([lex output file root], [ac_cv_prog_lex_root], [ +if test -f lex.yy.c; then + ac_cv_prog_lex_root=lex.yy +elif test -f lexyy.c; then + ac_cv_prog_lex_root=lexyy +else + AC_MSG_ERROR([cannot find output from $LEX; giving up]) +fi]) +AC_SUBST([LEX_OUTPUT_ROOT], [$ac_cv_prog_lex_root])dnl + +if test -z "${LEXLIB+set}"; then + AC_CACHE_CHECK([lex library], [ac_cv_lib_lex], [ + ac_save_LIBS=$LIBS + ac_cv_lib_lex='none needed' + for ac_lib in '' -lfl -ll; do + LIBS="$ac_lib $ac_save_LIBS" + AC_LINK_IFELSE([AC_LANG_DEFINES_PROVIDED[`cat $LEX_OUTPUT_ROOT.c`]], + [ac_cv_lib_lex=$ac_lib]) + test "$ac_cv_lib_lex" != 'none needed' && break + done + LIBS=$ac_save_LIBS + ]) + test "$ac_cv_lib_lex" != 'none needed' && LEXLIB=$ac_cv_lib_lex +fi +AC_SUBST(LEXLIB) + +AC_CACHE_CHECK(whether yytext is a pointer, ac_cv_prog_lex_yytext_pointer, +[# POSIX says lex can declare yytext either as a pointer or an array; the +# default is implementation-dependent. Figure out which it is, since +# not all implementations provide the %pointer and %array declarations. +ac_cv_prog_lex_yytext_pointer=no +ac_save_LIBS=$LIBS +LIBS="$LEXLIB $ac_save_LIBS" +AC_LINK_IFELSE([AC_LANG_DEFINES_PROVIDED + [#define YYTEXT_POINTER 1 +`cat $LEX_OUTPUT_ROOT.c`]], + [ac_cv_prog_lex_yytext_pointer=yes]) +LIBS=$ac_save_LIBS +]) +dnl +if test $ac_cv_prog_lex_yytext_pointer = yes; then + AC_DEFINE(YYTEXT_POINTER, 1, + [Define to 1 if `lex' declares `yytext' as a `char *' by default, + not a `char[]'.]) +fi +rm -f conftest.l $LEX_OUTPUT_ROOT.c +])# _AC_PROG_LEX_YYTEXT_DECL From a4e4295ad2c737bb64fc0b1fcb164a15e6b1f281 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 10 Apr 2012 21:19:59 +0200 Subject: [PATCH 12/22] build: flex.m4: quote properly. * m4/flex.m4: Use quotes more systematically. --- m4/flex.m4 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/m4/flex.m4 b/m4/flex.m4 index 3327bf9b..7e1b914e 100644 --- a/m4/flex.m4 +++ b/m4/flex.m4 @@ -12,7 +12,7 @@ AN_MAKEVAR([LEX], [AC_PROG_LEX]) AN_PROGRAM([lex], [AC_PROG_LEX]) AN_PROGRAM([flex], [AC_PROG_LEX]) AC_DEFUN_ONCE([AC_PROG_LEX], -[AC_CHECK_PROGS(LEX, flex lex, :) +[AC_CHECK_PROGS([LEX], [flex lex], [:]) if test "x$LEX" != "x:"; then _AC_PROG_LEX_YYTEXT_DECL fi]) @@ -43,7 +43,7 @@ main (void) return ! yylex () + ! yywrap (); } ]_ACEOF -_AC_DO_VAR(LEX conftest.l) +_AC_DO_VAR([LEX conftest.l]) AC_CACHE_CHECK([lex output file root], [ac_cv_prog_lex_root], [ if test -f lex.yy.c; then ac_cv_prog_lex_root=lex.yy @@ -68,9 +68,10 @@ if test -z "${LEXLIB+set}"; then ]) test "$ac_cv_lib_lex" != 'none needed' && LEXLIB=$ac_cv_lib_lex fi -AC_SUBST(LEXLIB) +AC_SUBST([LEXLIB]) -AC_CACHE_CHECK(whether yytext is a pointer, ac_cv_prog_lex_yytext_pointer, +AC_CACHE_CHECK([whether yytext is a pointer], + [ac_cv_prog_lex_yytext_pointer], [# POSIX says lex can declare yytext either as a pointer or an array; the # default is implementation-dependent. Figure out which it is, since # not all implementations provide the %pointer and %array declarations. @@ -85,7 +86,7 @@ LIBS=$ac_save_LIBS ]) dnl if test $ac_cv_prog_lex_yytext_pointer = yes; then - AC_DEFINE(YYTEXT_POINTER, 1, + AC_DEFINE([YYTEXT_POINTER], [1], [Define to 1 if `lex' declares `yytext' as a `char *' by default, not a `char[]'.]) fi From 0d49053a75ada3da6de8934fd9f4d08b8deb246a Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 10 Apr 2012 21:36:19 +0200 Subject: [PATCH 13/22] build: flex.m4: check for Flex. * m4/flex.m4 (_AC_PROG_LEX_YYTEXT_DECL): Check that $LEX supports some of the Flex options, and exclusive start conditions. Define FLEX to 'yes'/'', as AC_PROG_CC does for GCC. --- m4/flex.m4 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/m4/flex.m4 b/m4/flex.m4 index 7e1b914e..2073a0dc 100644 --- a/m4/flex.m4 +++ b/m4/flex.m4 @@ -20,10 +20,29 @@ fi]) # _AC_PROG_LEX_YYTEXT_DECL # ------------------------ -# Check for the Lex output root, the Lex library, and whether Lex -# declares yytext as a char * by default. +# Check whether this is Flex, for the Lex output root, the Lex library, +# and whether Lex declares yytext as a char * by default. m4_define([_AC_PROG_LEX_YYTEXT_DECL], +[AC_CACHE_CHECK([whether lex is flex], + [ac_cv_prog_flex], [cat >conftest.l <<_ACEOF[ +%option debug nodefault noinput nounput noyywrap never-interactive +%x SC_CONF_TEST +%% +a { BEGIN SC_CONF_TEST; } +]_ACEOF +if _AC_DO_VAR([LEX conftest.l]); then + ac_cv_prog_flex=yes +else + ac_cv_prog_flex=no +fi +]) +FLEX= +if test $ac_cv_prog_flex = yes; then + AC_SUBST([FLEX], [yes])dnl +fi + +cat >conftest.l <<_ACEOF[ %% a { ECHO; } b { REJECT; } From 10232af80816ac644f8b9d6659bf113026672f53 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 10 Apr 2012 21:36:23 +0200 Subject: [PATCH 14/22] build: require Flex. * configure.ac: Require Flex. --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index 688e18ef..704f5aaa 100644 --- a/configure.ac +++ b/configure.ac @@ -114,6 +114,9 @@ AC_SUBST([YACC_LIBRARY]) # Checks for programs. AC_PROG_LEX +if test "$FLEX" != yes; then + AC_MSG_ERROR([Flex is required]) +fi AC_PROG_YACC AC_PROG_RANLIB AC_PROG_GNU_M4 From a703b669b489ea2d3d4b5c9b37666293f7c97563 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 16 Apr 2012 16:34:00 +0200 Subject: [PATCH 15/22] tests: style changes. * tests/input.at: Use "print" in %printer instead of "destroy". It is unused, so we don't care, yet it is less surprising. * tests/actions.at: Comment changes. (cherry picked from commit abcd36ca1b658b108fc926f19cb9e45fb41daa65) --- tests/actions.at | 2 +- tests/input.at | 58 ++++++++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index bb2201db..22c3aa25 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -889,7 +889,7 @@ AT_CLEANUP AT_SETUP([Default %printer and %destructor for user-defined end token]) # _AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN(TYPED) -# ----------------------------------------------------------------------------- +# ------------------------------------------------------------- m4_define([_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN], [m4_if($1, 0, [m4_pushdef([kind], []) m4_pushdef([not_kind], [*])], diff --git a/tests/input.at b/tests/input.at index a60e0928..93ae3de1 100644 --- a/tests/input.at +++ b/tests/input.at @@ -182,53 +182,53 @@ AT_SETUP([Default %printer and %destructor redeclared]) AT_DATA([[input.y]], [[%destructor { destroy ($$); } <*> <*> -%printer { destroy ($$); } <*> <*> +%printer { print ($$); } <*> <*> %destructor { destroy ($$); } <*> -%printer { destroy ($$); } <*> +%printer { print ($$); } <*> %destructor { destroy ($$); } <> <> -%printer { destroy ($$); } <> <> +%printer { print ($$); } <> <> %destructor { destroy ($$); } <> -%printer { destroy ($$); } <> +%printer { print ($$); } <> %% start: ; %destructor { destroy ($$); } <*>; -%printer { destroy ($$); } <*>; +%printer { print ($$); } <*>; %destructor { destroy ($$); } <>; -%printer { destroy ($$); } <>; +%printer { print ($$); } <>; ]]) AT_BISON_CHECK([input.y], [1], [], [[input.y:1.13-29: redeclaration for default tagged %destructor input.y:1.13-29: previous declaration -input.y:2.10-26: redeclaration for default tagged %printer -input.y:2.10-26: previous declaration +input.y:2.10-24: redeclaration for default tagged %printer +input.y:2.10-24: previous declaration input.y:4.13-29: redeclaration for default tagged %destructor input.y:1.13-29: previous declaration -input.y:5.10-26: redeclaration for default tagged %printer -input.y:2.10-26: previous declaration +input.y:5.10-24: redeclaration for default tagged %printer +input.y:2.10-24: previous declaration input.y:7.13-29: redeclaration for default tagless %destructor input.y:7.13-29: previous declaration -input.y:8.10-26: redeclaration for default tagless %printer -input.y:8.10-26: previous declaration +input.y:8.10-24: redeclaration for default tagless %printer +input.y:8.10-24: previous declaration input.y:10.13-29: redeclaration for default tagless %destructor input.y:7.13-29: previous declaration -input.y:11.10-26: redeclaration for default tagless %printer -input.y:8.10-26: previous declaration +input.y:11.10-24: redeclaration for default tagless %printer +input.y:8.10-24: previous declaration input.y:17.13-29: redeclaration for default tagged %destructor input.y:4.13-29: previous declaration -input.y:18.10-26: redeclaration for default tagged %printer -input.y:5.10-26: previous declaration +input.y:18.10-24: redeclaration for default tagged %printer +input.y:5.10-24: previous declaration input.y:20.13-29: redeclaration for default tagless %destructor input.y:10.13-29: previous declaration -input.y:21.10-26: redeclaration for default tagless %printer -input.y:11.10-26: previous declaration +input.y:21.10-24: redeclaration for default tagless %printer +input.y:11.10-24: previous declaration ]]) AT_CLEANUP @@ -242,17 +242,17 @@ AT_SETUP([Per-type %printer and %destructor redeclared]) AT_DATA([[input.y]], [[%destructor { destroy ($$); } -%printer { destroy ($$); } +%printer { print ($$); } %destructor { destroy ($$); } -%printer { destroy ($$); } +%printer { print ($$); } %% start: ; %destructor { destroy ($$); } ; -%printer { destroy ($$); } ; +%printer { print ($$); } ; ]]) AT_BISON_CHECK([input.y], [1], [], @@ -260,18 +260,18 @@ AT_BISON_CHECK([input.y], [1], [], input.y:1.13-29: previous declaration input.y:4.13-29: %destructor redeclaration for input.y:4.13-29: previous declaration -input.y:5.10-26: %printer redeclaration for -input.y:2.10-26: previous declaration -input.y:5.10-26: %printer redeclaration for -input.y:5.10-26: previous declaration +input.y:5.10-24: %printer redeclaration for +input.y:2.10-24: previous declaration +input.y:5.10-24: %printer redeclaration for +input.y:5.10-24: previous declaration input.y:11.13-29: %destructor redeclaration for input.y:4.13-29: previous declaration input.y:11.13-29: %destructor redeclaration for input.y:1.13-29: previous declaration -input.y:12.10-26: %printer redeclaration for -input.y:2.10-26: previous declaration -input.y:12.10-26: %printer redeclaration for -input.y:5.10-26: previous declaration +input.y:12.10-24: %printer redeclaration for +input.y:2.10-24: previous declaration +input.y:12.10-24: %printer redeclaration for +input.y:5.10-24: previous declaration ]]) AT_CLEANUP From 56d60c19479822159e56960616cb3602e31f2a2c Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 8 Apr 2012 10:17:55 +0200 Subject: [PATCH 16/22] doc: mfcalc: demonstrate %printer. * doc/bison.texinfo (Printer Decl): New. Number mfcalc.y snippets so that they are output in the proper order. (The mfcalc Main): Use yydebug. (Debugging): Simplify the text. (Enabling Traces, Mfcalc Traces, The YYPRINT Macro): New. (Table of Symbols): Document YYPRINT and YYFPRINTF. (cherry picked from commit 93c150b666c3345bdd1527a5495a4787d8c3b5bf) Conflicts: doc/bison.texinfo --- doc/bison.texinfo | 361 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 330 insertions(+), 31 deletions(-) diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 86809c11..1a5b20c4 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -223,6 +223,7 @@ Bison Declarations * Type Decl:: Declaring the choice of type for a nonterminal symbol. * Initial Action Decl:: Code run before parsing starts. * Destructor Decl:: Declaring how symbols are freed. +* Printer Decl:: Declaring how symbol values are displayed. * Expect Decl:: Suppressing warnings about parsing conflicts. * Start Decl:: Specifying the start symbol. * Pure Decl:: Requesting a reentrant parser. @@ -295,6 +296,12 @@ Debugging Your Parser * Understanding:: Understanding the structure of your parser. * Tracing:: Tracing the execution of your parser. +Tracing Your Parser + +* Enabling Traces:: Activating run-time trace support +* Mfcalc Traces:: Extending @code{mfcalc} to support traces +* The YYPRINT Macro:: Obsolete interface for semantic value reports + Invoking Bison * Bison Options:: All the options described in detail, @@ -2286,7 +2293,7 @@ Note that multiple assignment and nested function calls are permitted. Here are the C and Bison declarations for the multi-function calculator. -@comment file: mfcalc.y +@comment file: mfcalc.y: 1 @example @group %@{ @@ -2296,6 +2303,7 @@ Here are the C and Bison declarations for the multi-function calculator. void yyerror (char const *); %@} @end group + @group %union @{ double val; /* For returning numbers. */ @@ -2303,7 +2311,7 @@ Here are the C and Bison declarations for the multi-function calculator. @} @end group %token NUM /* Simple double precision number. */ -%token VAR FNCT /* Variable and Function. */ +%token VAR FNCT /* Variable and function. */ %type exp @group @@ -2313,7 +2321,6 @@ Here are the C and Bison declarations for the multi-function calculator. %left NEG /* negation--unary minus */ %right '^' /* exponentiation */ @end group -%% /* The grammar follows. */ @end example The above grammar introduces only two new features of the Bison language. @@ -2345,8 +2352,9 @@ Here are the grammar rules for the multi-function calculator. Most of them are copied directly from @code{calc}; three rules, those which mention @code{VAR} or @code{FNCT}, are new. -@comment file: mfcalc.y +@comment file: mfcalc.y: 3 @example +%% /* The grammar follows. */ @group input: /* empty */ @@ -2431,6 +2439,7 @@ The new version of @code{main} includes a call to @code{init_table}, a function that initializes the symbol table. Here it is, and @code{init_table} as well: +@comment file: mfcalc.y: 3 @example #include @@ -2503,7 +2512,7 @@ linked to the front of the list, and a pointer to the object is returned. The function @code{getsym} is passed the name of the symbol to look up. If found, a pointer to that symbol is returned; otherwise zero is returned. -@comment file: mfcalc.y +@comment file: mfcalc.y: 3 @example #include /* malloc. */ #include /* strlen. */ @@ -2552,7 +2561,7 @@ returned to @code{yyparse}. No change is needed in the handling of numeric values and arithmetic operators in @code{yylex}. -@comment file: mfcalc.y +@comment file: mfcalc.y: 3 @example @group #include @@ -2634,6 +2643,36 @@ yylex (void) @end group @end example +The error reporting function is unchanged, and the new version of +@code{main} includes a call to @code{init_table} and sets the @code{yydebug} +on user demand (@xref{Tracing, , Tracing Your Parser}, for details): + +@comment file: mfcalc.y: 3 +@example +@group +/* Called by yyparse on error. */ +void +yyerror (char const *s) +@{ + fprintf (stderr, "%s\n", s); +@} +@end group + +@group +int +main (int argc, char const* argv[]) +@{ + int i; + /* Enable parse traces on option -p. */ + for (i = 1; i < argc; ++i) + if (!strcmp(argv[i], "-p")) + yydebug = 1; + init_table (); + return yyparse (); +@} +@end group +@end example + This program is both powerful and flexible. You may easily add new functions, and it is a simple job to modify this code to install predefined variables such as @code{pi} or @code{e} as well. @@ -4220,6 +4259,7 @@ and Context-Free Grammars}). * Type Decl:: Declaring the choice of type for a nonterminal symbol. * Initial Action Decl:: Code run before parsing starts. * Destructor Decl:: Declaring how symbols are freed. +* Printer Decl:: Declaring how symbol values are displayed. * Expect Decl:: Suppressing warnings about parsing conflicts. * Start Decl:: Specifying the start symbol. * Pure Decl:: Requesting a reentrant parser. @@ -4673,6 +4713,69 @@ error via @code{YYERROR} are not discarded automatically. As a rule of thumb, destructors are invoked only when user actions cannot manage the memory. +@node Printer Decl +@subsection Printing Semantic Values +@cindex printing semantic values +@findex %printer +@findex <*> +@findex <> +When run-time traces are enabled (@pxref{Tracing, ,Tracing Your Parser}), +the parser reports its actions, such as reductions. When a symbol involved +in an action is reported, only its kind is displayed, as the parser cannot +know how semantic values should be formatted. + +The @code{%printer} directive defines code that is called when a symbol is +reported. Its syntax is the same as @code{%destructor} (@pxref{Destructor +Decl, , Freeing Discarded Symbols}). + +@deffn {Directive} %printer @{ @var{code} @} @var{symbols} +@findex %printer +@vindex yyoutput +@c This is the same text as for %destructor. +Invoke the braced @var{code} whenever the parser displays one of the +@var{symbols}. Within @var{code}, @code{yyoutput} denotes the output stream +(a @code{FILE*} in C, and an @code{std::ostream&} in C++), +@code{$$} designates the semantic value associated with the symbol, and +@code{@@$} its location. The additional parser parameters are also +available (@pxref{Parser Function, , The Parser Function @code{yyparse}}). + +The @var{symbols} are defined as for @code{%destructor} (@pxref{Destructor +Decl, , Freeing Discarded Symbols}.): they can be per-type (e.g., +@samp{}), per-symbol (e.g., @samp{exp}, @samp{NUM}, @samp{"float"}), +typed per-default (i.e., @samp{<*>}, or untyped per-default (i.e., +@samp{<>}). +@end deffn + +@noindent +For example: + +@example +%union @{ char *string; @} +%token STRING1 +%token STRING2 +%type string1 +%type string2 +%union @{ char character; @} +%token CHR +%type chr +%token TAGLESS + +%printer @{ fprintf (yyoutput, "'%c'", $$); @} +%printer @{ fprintf (yyoutput, "&%p", $$); @} <*> +%printer @{ fprintf (yyoutput, "\"%s\"", $$); @} STRING1 string1 +%printer @{ fprintf (yyoutput, "<>"); @} <> +@end example + +@noindent +guarantees that, when the parser print any symbol that has a semantic type +tag other than @code{}, it display the address of the semantic +value by default. However, when the parser displays a @code{STRING1} or a +@code{string1}, it formats it as a string in double quotes. It performs +only the second @code{%printer} in this case, so it prints only once. +Finally, the parser print @samp{<>} for any symbol, such as @code{TAGLESS}, +that has no semantic type tag. See also + + @node Expect Decl @subsection Suppressing Conflict Warnings @cindex suppressing conflict warnings @@ -7882,12 +7985,10 @@ clear the flag. @node Debugging @chapter Debugging Your Parser -Developing a parser can be a challenge, especially if you don't -understand the algorithm (@pxref{Algorithm, ,The Bison Parser -Algorithm}). Even so, sometimes a detailed description of the automaton -can help (@pxref{Understanding, , Understanding Your Parser}), or -tracing the execution of the parser can give some insight on why it -behaves improperly (@pxref{Tracing, , Tracing Your Parser}). +Developing a parser can be a challenge, especially if you don't understand +the algorithm (@pxref{Algorithm, ,The Bison Parser Algorithm}). This +chapter explains how to generate and read the detailed description of the +automaton, and how to enable and understand the parser run-time traces. @menu * Understanding:: Understanding the structure of your parser. @@ -8314,9 +8415,17 @@ associativity of @samp{/} is not specified. @cindex debugging @cindex tracing the parser -If a Bison grammar compiles properly but doesn't do what you want when it -runs, the @code{yydebug} parser-trace feature can help you figure out why. +When a Bison grammar compiles properly but parses ``incorrectly'', the +@code{yydebug} parser-trace feature helps figuring out why. +@menu +* Enabling Traces:: Activating run-time trace support +* Mfcalc Traces:: Extending @code{mfcalc} to support traces +* The YYPRINT Macro:: Obsolete interface for semantic value reports +@end menu + +@node Enabling Traces +@subsection Enabling Traces There are several means to enable compilation of trace facilities: @table @asis @@ -8345,6 +8454,7 @@ the preferred solution. We suggest that you always enable the debug option so that debugging is always possible. +@findex YYFPRINTF The trace facility outputs messages with macro calls of the form @code{YYFPRINTF (stderr, @var{format}, @var{args})} where @var{format} and @var{args} are the usual @code{printf} format and variadic @@ -8374,9 +8484,9 @@ Each time a rule is reduced, which rule it is, and the complete contents of the state stack afterward. @end itemize -To make sense of this information, it helps to refer to the listing file -produced by the Bison @samp{-v} option (@pxref{Invocation, ,Invoking -Bison}). This file shows the meaning of each state in terms of +To make sense of this information, it helps to refer to the automaton +description file (@pxref{Understanding, ,Understanding Your Parser}). +This file shows the meaning of each state in terms of positions in various rules, and also what each state will do with each possible input token. As you read the successive trace messages, you can see that the parser is functioning according to its specification in @@ -8384,19 +8494,197 @@ the listing file. Eventually you will arrive at the place where something undesirable happens, and you will see which parts of the grammar are to blame. -The parser implementation file is a C program and you can use C +The parser implementation file is a C/C++/Java program and you can use debuggers on it, but it's not easy to interpret what it is doing. The parser function is a finite-state machine interpreter, and aside from the actions it executes the same code over and over. Only the values of variables show where in the grammar it is working. +@node Mfcalc Traces +@subsection Enabling Debug Traces for @code{mfcalc} + +The debugging information normally gives the token type of each token read, +but not its semantic value. The @code{%printer} directive allows specify +how semantic values are reported, see @ref{Printer Decl, , Printing +Semantic Values}. For backward compatibility, Yacc like C parsers may also +use the @code{YYPRINT} (@pxref{The YYPRINT Macro, , The @code{YYPRINT} +Macro}), but its use is discouraged. + +As a demonstration of @code{%printer}, consider the multi-function +calculator, @code{mfcalc} (@pxref{Multi-function Calc}). To enable run-time +traces, and semantic value reports, insert the following directives in its +prologue: + +@comment file: mfcalc.y: 2 +@example +/* Generate the parser description file. */ +%verbose +/* Enable run-time traces (yydebug). */ +%define parse.trace + +/* Formatting semantic values. */ +%printer @{ fprintf (yyoutput, "%s", $$->name); @} VAR; +%printer @{ fprintf (yyoutput, "%s()", $$->name); @} FNCT; +%printer @{ fprintf (yyoutput, "%g", $$); @} ; +@end example + +The @code{%define} directive instructs Bison to generate run-time trace +support. Then, activation of these traces is controlled at run-time by the +@code{yydebug} variable, which is disabled by default. Because these traces +will refer to the ``states'' of the parser, it is helpful to ask for the +creation of a description of that parser; this is the purpose of (admittedly +ill-named) @code{%verbose} directive. + +The set of @code{%printer} directives demonstrates how to format the +semantic value in the traces. Note that the specification can be done +either on the symbol type (e.g., @code{VAR} or @code{FNCT}), or on the type +tag: since @code{} is the type for both @code{NUM} and @code{exp}, this +printer will be used for them. + +Here is a sample of the information provided by run-time traces. The traces +are sent onto standard error. + +@example +$ @kbd{echo 'sin(1-1)' | ./mfcalc -p} +Starting parse +Entering state 0 +Reducing stack by rule 1 (line 34): +-> $$ = nterm input () +Stack now 0 +Entering state 1 +@end example + +@noindent +This first batch shows a specific feature of this grammar: the first rule +(which is in line 34 of @file{mfcalc.y} can be reduced without even having +to look for the first token. The resulting left-hand symbol (@code{$$}) is +a valueless (@samp{()}) @code{input} non terminal (@code{nterm}). + +Then the parser calls the scanner. +@example +Reading a token: Next token is token FNCT (sin()) +Shifting token FNCT (sin()) +Entering state 6 +@end example + +@noindent +That token (@code{token}) is a function (@code{FNCT}) whose value is +@samp{sin} as formatted per our @code{%printer} specification: @samp{sin()}. +The parser stores (@code{Shifting}) that token, and others, until it can do +something about it. + +@example +Reading a token: Next token is token '(' () +Shifting token '(' () +Entering state 14 +Reading a token: Next token is token NUM (1.000000) +Shifting token NUM (1.000000) +Entering state 4 +Reducing stack by rule 6 (line 44): + $1 = token NUM (1.000000) +-> $$ = nterm exp (1.000000) +Stack now 0 1 6 14 +Entering state 24 +@end example + +@noindent +The previous reduction demonstrates the @code{%printer} directive for +@code{}: both the token @code{NUM} and the resulting non-terminal +@code{exp} have @samp{1} as value. + +@example +Reading a token: Next token is token '-' () +Shifting token '-' () +Entering state 17 +Reading a token: Next token is token NUM (1.000000) +Shifting token NUM (1.000000) +Entering state 4 +Reducing stack by rule 6 (line 44): + $1 = token NUM (1.000000) +-> $$ = nterm exp (1.000000) +Stack now 0 1 6 14 24 17 +Entering state 26 +Reading a token: Next token is token ')' () +Reducing stack by rule 11 (line 49): + $1 = nterm exp (1.000000) + $2 = token '-' () + $3 = nterm exp (1.000000) +-> $$ = nterm exp (0.000000) +Stack now 0 1 6 14 +Entering state 24 +@end example + +@noindent +The rule for the subtraction was just reduced. The parser is about to +discover the end of the call to @code{sin}. + +@example +Next token is token ')' () +Shifting token ')' () +Entering state 31 +Reducing stack by rule 9 (line 47): + $1 = token FNCT (sin()) + $2 = token '(' () + $3 = nterm exp (0.000000) + $4 = token ')' () +-> $$ = nterm exp (0.000000) +Stack now 0 1 +Entering state 11 +@end example + +@noindent +Finally, the end-of-line allow the parser to complete the computation, and +display its result. + +@example +Reading a token: Next token is token '\n' () +Shifting token '\n' () +Entering state 22 +Reducing stack by rule 4 (line 40): + $1 = nterm exp (0.000000) + $2 = token '\n' () +@result{} 0 +-> $$ = nterm line () +Stack now 0 1 +Entering state 10 +Reducing stack by rule 2 (line 35): + $1 = nterm input () + $2 = nterm line () +-> $$ = nterm input () +Stack now 0 +Entering state 1 +@end example + +The parser has returned into state 1, in which it is waiting for the next +expression to evaluate, or for the end-of-file token, which causes the +completion of the parsing. + +@example +Reading a token: Now at end of input. +Shifting token $end () +Entering state 2 +Stack now 0 1 2 +Cleanup: popping token $end () +Cleanup: popping nterm input () +@end example + + +@node The YYPRINT Macro +@subsection The @code{YYPRINT} Macro + @findex YYPRINT -The debugging information normally gives the token type of each token -read, but not its semantic value. You can optionally define a macro -named @code{YYPRINT} to provide a way to print the value. If you define -@code{YYPRINT}, it should take three arguments. The parser will pass a -standard I/O stream, the numeric code for the token type, and the token -value (from @code{yylval}). +Before @code{%printer} support, semantic values could be displayed using the +@code{YYPRINT} macro, which works only for terminal symbols and only with +the @file{yacc.c} skeleton. + +@deffn {Macro} YYPRINT (@var{stream}, @var{token}, @var{value}); +@findex YYPRINT +If you define @code{YYPRINT}, it should take three arguments. The parser +will pass a standard I/O stream, the numeric code for the token type, and +the token value (from @code{yylval}). + +For @file{yacc.c} only. Obsoleted by @code{%printer}. +@end deffn Here is an example of @code{YYPRINT} suitable for the multi-function calculator (@pxref{Mfcalc Declarations, ,Declarations for @code{mfcalc}}): @@ -8404,8 +8692,8 @@ calculator (@pxref{Mfcalc Declarations, ,Declarations for @code{mfcalc}}): @example %@{ static void print_token_value (FILE *, int, YYSTYPE); - #define YYPRINT(file, type, value) \ - print_token_value (file, type, value) + #define YYPRINT(File, Type, Value) \ + print_token_value (File, Type, Value) %@} @dots{} %% @dots{} %% @dots{} @@ -9538,7 +9826,7 @@ void calcxx_driver::scan_begin () @{ yy_flex_debug = trace_scanning; - if (file == "-") + if (file.empty () || file == "-") yyin = stdin; else if (!(yyin = fopen (file.c_str (), "r"))) @{ @@ -9572,12 +9860,12 @@ int main (int argc, char *argv[]) @{ calcxx_driver driver; - for (++argv; argv[0]; ++argv) - if (*argv == std::string ("-p")) + for (int i = 1; i < argc; ++i) + if (argv[i] == std::string ("-p")) driver.trace_parsing = true; - else if (*argv == std::string ("-s")) + else if (argv[i] == std::string ("-s")) driver.trace_scanning = true; - else if (!driver.parse (*argv)) + else if (!driver.parse (argv[i])) std::cout << driver.result << std::endl; @} @end group @@ -10932,6 +11220,11 @@ use for @code{YYERROR_VERBOSE}, just whether you define it. Using @code{%error-verbose} is preferred. @xref{Error Reporting}. @end deffn +@deffn {Macro} YYFPRINTF +Macro used to output run-time traces. +@xref{Enabling Traces}. +@end deffn + @deffn {Macro} YYINITDEPTH Macro for specifying the initial size of the parser stack. @xref{Memory Management}. @@ -10994,6 +11287,12 @@ The parser function produced by Bison; call this function to start parsing. @xref{Parser Function, ,The Parser Function @code{yyparse}}. @end deffn +@deffn {Macro} YYPRINT +Macro used to output token semantic values. For @file{yacc.c} only. +Obsoleted by @code{%printer}. +@xref{The YYPRINT Macro, , The @code{YYPRINT} Macro}. +@end deffn + @deffn {Function} yypstate_delete The function to delete a parser instance, produced by Bison in push mode; call this function to delete the memory associated with a parser. From 68fff38a09c92653f386aab7853b07da9e2f1ebc Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 16 Apr 2012 17:03:19 +0200 Subject: [PATCH 17/22] %printer: support both yyo and yyoutput. lalr1.cc used to support yyo, but not yyoutput. Support both, but document only yyoutput (at least until there is some consensus on this). * data/c.m4 (yy_symbol_value_print): Also support yyo. * data/glr.cc (yy_symbol_value_print_): Support both yyo and yyoutput. * data/lalr1.cc: Also support yyoutput. * doc/bison.texinfo: Explicitly use yyoutput in the examples. * examples/mfcalc/mfcalc.test: Test the -p option. (cherry picked from commit c50263271db482261b11f7452283c142a780a09d) Conflicts: data/c.m4 data/lalr1.cc doc/bison.texinfo etc/Makefile.am --- data/c.m4 | 2 ++ data/glr.cc | 6 ++++-- data/lalr1.cc | 3 +++ doc/bison.texinfo | 8 ++++---- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/data/c.m4 b/data/c.m4 index 195c441d..fee006a3 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -456,6 +456,8 @@ m4_define_default([b4_yy_symbol_print_generate], b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; ]b4_locations_if([ YYUSE (yylocationp); diff --git a/data/glr.cc b/data/glr.cc index 0f9141c4..b7a8b40d 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -151,9 +151,11 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype, const semantic_type* yyvaluep, const location_type* yylocationp) { - /* Pacify ``unused variable'' warnings. */ - YYUSE (yyvaluep); YYUSE (yylocationp); + YYUSE (yyvaluep); + std::ostream& yyoutput = debug_stream (); + std::ostream& yyo = yyoutput; + YYUSE (yyo); switch (yytype) { ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl diff --git a/data/lalr1.cc b/data/lalr1.cc index d7201dd4..76a83504 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -446,6 +446,9 @@ do { \ { YYUSE (yylocationp); YYUSE (yyvaluep); + std::ostream& yyo = debug_stream (); + std::ostream& yyoutput = yyo; + YYUSE (yyoutput); switch (yytype) { ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 1a5b20c4..0e9329fb 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -3079,14 +3079,14 @@ type: %code requires @{ #include "type1.h" @} %union @{ type1 field1; @} %destructor @{ type1_free ($$); @} -%printer @{ type1_print ($$); @} +%printer @{ type1_print (yyoutput, $$); @} @end group @group %code requires @{ #include "type2.h" @} %union @{ type2 field2; @} %destructor @{ type2_free ($$); @} -%printer @{ type2_print ($$); @} +%printer @{ type2_print (yyoutput, $$); @} @end group @end example @@ -9665,10 +9665,10 @@ To enable memory deallocation during error recovery, use @c FIXME: Document %printer, and mention that it takes a braced-code operand. @comment file: calc++-parser.yy @example -%printer @{ debug_stream () << *$$; @} "identifier" +%printer @{ yyoutput << *$$; @} "identifier" %destructor @{ delete $$; @} "identifier" -%printer @{ debug_stream () << $$; @} +%printer @{ yyoutput << $$; @} @end example @noindent From 7e508a2b2d494f32d171ac9376a80ae2b75480c3 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 16 Apr 2012 17:53:15 +0200 Subject: [PATCH 18/22] NEWS: Update. * NEWS: Spell check. (%printer): is now documented. --- NEWS | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index b49f2c84..64d82488 100644 --- a/NEWS +++ b/NEWS @@ -39,7 +39,18 @@ Bison News ** liby is no longer asking for "rpl_fprintf" on some platforms. -** Several improvements have been made to the manual: +** Changes in the manual: + +*** %printer is documented + + The %printer directive, supported since at least Bison 1.50, is + finally documented. The %mfcalc example is extended to demonstrate + its use of printer. + + The C++ parsers now also support yyoutput (as an alias to + debug_stream ()) for consistency with the C skeletons. + +*** Several improvements have been made: The layout for grammar excerpts was changed to a more compact scheme. Named references are motivated. The description of the @@ -1458,7 +1469,7 @@ Bison News ** The output file does not define const, as this caused problems when used with common autoconfiguration schemes. If you still use ancient compilers that lack const, compile with the equivalent of the C compiler option - `-Dconst='. autoconf's AC_C_CONST macro provides one way to do this. + `-Dconst='. Autoconf's AC_C_CONST macro provides one way to do this. ** Added `-g' and `--graph'. @@ -1505,7 +1516,7 @@ Bison News * Changes in version 1.26: -** Bison now uses automake. +** Bison now uses Automake. ** New mailing lists: and . @@ -1527,7 +1538,7 @@ the grammar file, and reports all the errors found in it. ** Tokens can now be specified as multiple-character strings: for example, you could use "<=" for a token which looks like <=, instead -of chosing a name like LESSEQ. +of choosing a name like LESSEQ. ** The %token_table declaration says to write a table of tokens (names and numbers) into the parser file. The yylex function can use this @@ -1562,10 +1573,6 @@ Line numbers in output file corrected. Output file does not redefine const for C++. -Local Variables: -mode: outline -End: - ----- Copyright (C) 1995-2012 Free Software Foundation, Inc. @@ -1584,3 +1591,24 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . + + LocalWords: yacc YYBACKUP glr GCC lalr ArrayIndexOutOfBoundsException nullptr + LocalWords: cplusplus liby rpl fprintf mfcalc Wyacc stmt cond expr mk sym lr + LocalWords: IELR ielr Lookahead YYERROR nonassoc LALR's api lookaheads yychar + LocalWords: destructor lookahead YYRHSLOC YYLLOC Rhs ifndef YYFAIL cpp sr rr + LocalWords: preprocessor initializer Wno Wnone Werror FreeBSD prec livelocks + LocalWords: Solaris AIX UX RHEL Tru LHS gcc's Wundef YYENABLE NLS YYLTYPE VCG + LocalWords: yyerror cpp's Wunused yylval yylloc prepend yyparse yylex yypush + LocalWords: Graphviz xml nonterminals midrule destructor's YYSTYPE typedef ly + LocalWords: CHR chr printf stdout namespace preprocessing enum pre include's + LocalWords: YYRECOVERING nonfree destructors YYABORT YYACCEPT params enums de + LocalWords: struct yystype DJGPP lex param Haible NUM alloca YYSTACK NUL goto + LocalWords: YYMAXDEPTH Unescaped UCNs YYLTYPE's yyltype typedefs inline Yaccs + LocalWords: Heriyanto Reenable dprec Hilfinger Eggert MYEOF Folle Menezes EOF + LocalWords: Lackovic define's itemset Groff Gettext malloc NEWS'ed YYDEBUG + LocalWords: namespaces strerror const autoconfiguration Dconst Autoconf's FDL + LocalWords: Automake TMPDIR LESSEQ + +Local Variables: +mode: outline +End: From 8ef26c2aa7a53421234191b85c4070d7c16dbdb5 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 16 Apr 2012 17:56:52 +0200 Subject: [PATCH 19/22] install-pdf: fix. * gnulib: Fix install-pdf in po/ and runtime-po/. Reported by Hans Aberg. Fixed by Joel E. Denny. http://lists.gnu.org/archive/html/bug-bison/2011-05/msg00008.html --- NEWS | 11 +++++++++-- bootstrap | 7 +++++-- gnulib | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 64d82488..f6cc360a 100644 --- a/NEWS +++ b/NEWS @@ -58,14 +58,21 @@ Bison News format. Incorrect index entries were fixed. Some other errors were fixed. -** Warnings during the build procedure have been eliminated. +** Changes to the build system: -** Several portability problems in the test suite have been fixed: +*** Warnings during the build procedure have been eliminated. + +*** Several portability problems in the test suite have been fixed: This includes warnings with some compilers, unexpected behavior of tools such as diff, warning messages from the test suite itself, etc. +*** The install-pdf target work properly: + + Running "make install-pdf" (or -dvi, -html, -info, and -ps) no + longer halts in the middle of its course. + * Changes in version 2.5 (2011-05-14): ** Grammar symbol names can now contain non-initial dashes: diff --git a/bootstrap b/bootstrap index 31eb651f..2abf9bd6 100755 --- a/bootstrap +++ b/bootstrap @@ -1,6 +1,6 @@ #! /bin/sh # Print a version string. -scriptversion=2012-02-11.09; # UTC +scriptversion=2012-04-16.16; # UTC # Bootstrap this package from checked-out sources. @@ -847,7 +847,8 @@ for file in $gnulib_extra_files; do esac symlink_to_dir "$GNULIB_SRCDIR" $file $dst || exit done - +pwd +set -xv if test $with_gettext = yes; then # Create gettext configuration. echo "$0: Creating po/Makevars from po/Makevars.template ..." @@ -863,6 +864,8 @@ if test $with_gettext = yes; then } ' po/Makevars.template >po/Makevars || exit 1 + cat $build_aux/po/Makefile.in.in > po/Makefile.in.in || exit 1 + if test -d runtime-po; then # Similarly for runtime-po/Makevars, but not quite the same. rm -f runtime-po/Makevars diff --git a/gnulib b/gnulib index 55cc8db0..1a0e0aef 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 55cc8db041f845c2e82ed10aa192ac200ab3f530 +Subproject commit 1a0e0aefd4b1fbef0c6e5d990bc01499fd153a0d From fbca8023edaf1e978fb16c0a104180eac5a1618e Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 16 Apr 2012 19:18:58 +0200 Subject: [PATCH 20/22] build: fix previous commit. * bootstrap: Update from gnulib. --- bootstrap | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bootstrap b/bootstrap index 2abf9bd6..16dc15c9 100755 --- a/bootstrap +++ b/bootstrap @@ -847,8 +847,7 @@ for file in $gnulib_extra_files; do esac symlink_to_dir "$GNULIB_SRCDIR" $file $dst || exit done -pwd -set -xv + if test $with_gettext = yes; then # Create gettext configuration. echo "$0: Creating po/Makevars from po/Makevars.template ..." @@ -864,7 +863,7 @@ if test $with_gettext = yes; then } ' po/Makevars.template >po/Makevars || exit 1 - cat $build_aux/po/Makefile.in.in > po/Makefile.in.in || exit 1 + cat $GNULIB_SRCDIR/build-aux/po/Makefile.in.in > po/Makefile.in.in || exit 1 if test -d runtime-po; then # Similarly for runtime-po/Makevars, but not quite the same. From 2ba031129ab69496de3d218aafa9022bd9fca4e2 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 8 Apr 2012 10:17:58 +0200 Subject: [PATCH 21/22] doc: fix some invalid @ref. * doc/bison.texinfo: Fix incorrect @ref uses. (cherry picked from commit e3fd1dcb8b0b55525876440410f71791d8b4c2f3) --- doc/bison.texinfo | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 0e9329fb..b9b7f775 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -8005,7 +8005,7 @@ tune or simply fix a parser. Bison provides two different representation of it, either textually or graphically (as a DOT file). The textual file is generated when the options @option{--report} or -@option{--verbose} are specified, see @xref{Invocation, , Invoking +@option{--verbose} are specified, see @ref{Invocation, , Invoking Bison}. Its name is made by removing @samp{.tab.c} or @samp{.c} from the parser implementation file name, and adding @samp{.output} instead. Therefore, if the grammar file is @file{foo.y}, then the @@ -10252,7 +10252,7 @@ macros. Instead, they should be preceded by @code{return} when they appear in an action. The actual definition of these symbols is opaque to the Bison grammar, and it might change in the future. The only meaningful operation that you can do, is to return them. -See @pxref{Java Action Features}. +@xref{Java Action Features}. Note that of these three symbols, only @code{YYACCEPT} and @code{YYABORT} will cause a return from the @code{yyparse} @@ -10268,8 +10268,8 @@ values have a common base type: @code{Object} or as specified by an union. The type of @code{$$}, even with angle brackets, is the base type since Java casts are not allow on the left-hand side of assignments. Also, @code{$@var{n}} and @code{@@@var{n}} are not allowed on the -left-hand side of assignments. See @pxref{Java Semantic Values} and -@pxref{Java Action Features}. +left-hand side of assignments. @xref{Java Semantic Values} and +@ref{Java Action Features}. @item The prologue declarations have a different meaning than in C/C++ code. @@ -10285,7 +10285,7 @@ blocks are placed inside the parser class. @item @code{%code lexer} blocks, if specified, should include the implementation of the scanner. If there is no such block, the scanner can be any class -that implements the appropriate interface (see @pxref{Java Scanner +that implements the appropriate interface (@pxref{Java Scanner Interface}). @end table From 95e343fea3fa47b88ec91d63d1b8579d7890719f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 17 Apr 2012 16:50:52 +0200 Subject: [PATCH 22/22] tests: ignore code coverage/profiling failure messages The Hydra buildfarm provides code coverage analysis. For some reason, in some test cases, code coverage data seem to be incompatible, and generate error messages at parser run-time. Ignore these messages so that (i) these tests do pass, (ii) coverage results be provided by Hydra. * tests/local.at (AT_PARSER_CHECK): Ignore messages for failed merges of code coverage/profiling results. --- tests/local.at | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/local.at b/tests/local.at index d651eb95..7e88408f 100644 --- a/tests/local.at +++ b/tests/local.at @@ -461,17 +461,26 @@ m4_define([AT_FULL_COMPILE], [ ## Running a generated parser. ## ## ---------------------------- ## + # AT_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE]) # ------------------------------------------------------------ # So that we can run `./testsuite PREPARSER='valgrind -q' for instance. +# +# Get rid of spurious messages when compiled with --coverage: +# +profiling:/[...]/lib/fprintf.gcda:Merge mismatch for summaries m4_define([AT_PARSER_CHECK], -[AT_CHECK([$5 $PREPARSER $1], [$2], [$3], [$4])]) +[AT_CHECK([$5 $PREPARSER $1], [$2], [$3], [stderr]) +AT_CHECK([sed >&2 -e '/^profiling:.*:Merge mismatch for summaries/d' stderr], + [0], [], [$4]) +]) + # AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE]) # ----------------------------------------------------------------- m4_define([AT_JAVA_PARSER_CHECK], [AT_CHECK([$5[ $SHELL ../../../javaexec.sh ]$1], [$2], [$3], [$4])]) + # AT_TEST_TABLES_AND_PARSE(TITLE, COND-VALUE, TEST-SPEC, # DECLS, GRAMMAR, INPUT, # BISON-STDERR, TABLES-OR-LAST-STATE,