From 7649ec0d9823518bf8ffaaa6e816da77e005cea4 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 19 Aug 2019 19:06:43 +0200
Subject: [PATCH 1/2] Import byacc-20190617

---
 contrib/byacc/CHANGES   | 249 +++++++++++++++++++++++++++++++++++++++-
 contrib/byacc/VERSION   |   2 +-
 contrib/byacc/defs.h    |  50 +++++++-
 contrib/byacc/main.c    |  26 ++++-
 contrib/byacc/output.c  |  42 +++++--
 contrib/byacc/reader.c  |   7 +-
 contrib/byacc/yacc.1    | 144 +++++++++++++----------
 contrib/byacc/yaccpar.c |   7 +-
 8 files changed, 439 insertions(+), 88 deletions(-)

diff --git a/contrib/byacc/CHANGES b/contrib/byacc/CHANGES
index c094671271..0265ec2544 100644
--- a/contrib/byacc/CHANGES
+++ b/contrib/byacc/CHANGES
@@ -1,3 +1,246 @@
+2019-06-17  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* test/btyacc/big_b.error, test/btyacc/big_l.error, test/btyacc/help.error, test/btyacc/no_b_opt.error, test/btyacc/no_output2.error, test/btyacc/no_p_opt.error, test/btyacc/nostdin.error, test/yacc/big_b.error, test/yacc/big_l.error, test/yacc/help.error, test/yacc/no_b_opt.error, test/yacc/no_output2.error, test/yacc/no_p_opt.error, test/yacc/nostdin.error:
+	regen
+
+	* test/run_test.sh: test "-H" rather than "-D"
+
+2019-06-16  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* main.c, yacc.1:
+	change "-D" option to "-H" (discussion with Ethan Sommer)
+
+	* VERSION, package/byacc.spec, package/debian/changelog, package/mingw-byacc.spec, package/pkgsrc/Makefile:
+	bump
+
+	* test/btyacc/defines1.calc.c, test/btyacc/defines2.calc.c, test/btyacc/defines3.calc.c:
+	RCS_BASE
+
+	* test/run_test.sh: in test_defines, save the ".c" file too
+
+	* test/yacc/defines3.calc.c, test/yacc/defines2.calc.c, test/yacc/defines1.calc.c:
+	RCS_BASE
+
+	* test/run_test.sh:
+	output of test_defines should be a header ".h", not ".c"
+
+	* test/btyacc/defines1.calc.h, test/btyacc/defines1.error, test/btyacc/defines1.output, test/btyacc/defines2.calc.h, test/btyacc/defines2.error, test/btyacc/defines2.output, test/btyacc/defines3.calc.h, test/btyacc/defines3.error, test/btyacc/defines3.output:
+	RCS_BASE
+
+	* main.c: however, a subsequent -d cancels -D
+
+	* test/yacc/defines1.calc.h, test/yacc/defines3.calc.h: RCS_BASE
+
+	* main.c: -D option implies -d
+
+	* test/yacc/defines1.error, test/yacc/defines1.output, test/yacc/defines2.calc.h, test/yacc/defines2.error, test/yacc/defines2.output, test/yacc/defines3.error, test/yacc/defines3.output:
+	RCS_BASE
+
+	* yacc.1: align macro definitions with my other manpages
+
+	* test/run_test.sh: add test for -D after -d or -b options
+
+	* test/btyacc/stdin1.calc.c, test/btyacc/stdin1.error, test/btyacc/stdin1.output, test/btyacc/stdin2.calc.c, test/btyacc/stdin2.error, test/btyacc/stdin2.output:
+	RCS_BASE
+
+	* test/btyacc/big_b.error, test/btyacc/big_b.output, test/btyacc/big_l.error, test/btyacc/big_l.output, test/btyacc/help.error, test/btyacc/help.output, test/btyacc/no_b_opt.error, test/btyacc/no_b_opt.output, test/btyacc/no_b_opt1.error, test/btyacc/no_b_opt1.output, test/btyacc/no_code_c.error, test/btyacc/no_code_c.output, test/btyacc/no_defines.error, test/btyacc/no_defines.output, test/btyacc/no_graph.error, test/btyacc/no_graph.output, test/btyacc/no_include.error, test/btyacc/no_include.output, test/btyacc/no_opts.error, test/btyacc/no_opts.output, test/btyacc/no_output.error, test/btyacc/no_output.output, test/btyacc/no_output1.error, test/btyacc/no_output1.output, test/btyacc/no_output2.error, test/btyacc/no_output2.output, test/btyacc/no_p_opt.error, test/btyacc/no_p_opt.output, test/btyacc/no_p_opt1.error, test/btyacc/no_p_opt1.output, test/btyacc/no_verbose.error, test/btyacc/no_verbose.output, test/btyacc/nostdin.error, test/btyacc/nostdin.output, test/yacc/big_b.error, test/yacc/big_b.output, test/yacc/big_l.error, test/yacc/big_l.output, test/yacc/help.error, test/yacc/help.output, test/yacc/no_b_opt.error, test/yacc/no_b_opt.output, test/yacc/no_b_opt1.error, test/yacc/no_b_opt1.output, test/yacc/no_code_c.error, test/yacc/no_code_c.output, test/yacc/no_defines.error, test/yacc/no_defines.output, test/yacc/no_graph.error, test/yacc/no_graph.output, test/yacc/no_include.error, test/yacc/no_include.output, test/yacc/no_opts.error, test/yacc/no_opts.output, test/yacc/no_output.error, test/yacc/no_output.output, test/yacc/no_output1.error, test/yacc/no_output1.output, test/yacc/no_output2.error, test/yacc/no_output2.output, test/yacc/no_p_opt.error, test/yacc/no_p_opt.output, test/yacc/no_p_opt1.error, test/yacc/no_p_opt1.output, test/yacc/no_verbose.error, test/yacc/no_verbose.output, test/yacc/nostdin.error, test/yacc/nostdin.output:
+	regen
+
+	* test/run_test.sh:
+	add a test for stdin "-" vs end-options "--", and correct a redirection
+	of stderr in test_flags
+
+	* test/yacc/stdin2.output, test/yacc/stdin2.calc.c, test/yacc/stdin1.calc.c, test/yacc/stdin1.error, test/yacc/stdin1.output, test/yacc/stdin2.error:
+	RCS_BASE
+
+	* test/btyacc/big_b.output, test/btyacc/big_l.output, test/btyacc/help.output, test/btyacc/no_b_opt.output, test/btyacc/no_output2.output, test/btyacc/no_p_opt.output, test/btyacc/nostdin.output, test/yacc/big_b.output, test/yacc/big_l.output, test/yacc/help.output, test/yacc/no_b_opt.output, test/yacc/no_output2.output, test/yacc/no_p_opt.output, test/yacc/nostdin.output:
+	regen
+
+	* main.c: add -D option, to specify filename vs y.tab.h for -d
+
+	* defs.h: add dflag2, for -D option
+
+	* yacc.1: document -D option
+
+	* config_h.in: updated with autoheader-252
+
+	* configure: regen
+
+	* package/debian/copyright: bump
+
+	* aclocal.m4: add CF_GETOPT_HEADER
+
+	* aclocal.m4: Improved autoconf macros:
+	+ CF_CC_ENV_FLAGS
+		putting preprocessor flags in CFLAGS also is a nuisance, which can be
+		addressed in the same way.
+	+ CF_GCC_WARNINGS
+		factor out workaround for XTSTRINGDEFINES as CF_CONST_X_STRING
+	+ CF_GNU_SOURCE
+		The check for _DEFAULT_SOURCE should apply to "recent" Cygwin (since early 2016),
+		and except for "NEWLIB" vs "GLIBC" in the test, acts the same if I pretend
+		that "newlib" is the GNU C library.  Without this, the check falls through
+		to the _XOPEN_SOURCE test, which breaks the pseudoterminal checks for xterm.
+	+ CF_POSIX_C_SOURCE
+		add/use CF_POSIX_VISIBLE
+	+ CF_TRY_XOPEN_SOURCE
+		use CF_APPEND_TEXT
+	+ CF_WITH_MAN2HTML
+		use sed to work around non-POSIX tail utility
+	+ CF_XOPEN_SOURCE
+		use CF_APPEND_TEXT
+		add/use CF_POSIX_VISIBLE
+
+	* VERSION, package/byacc.spec, package/debian/changelog, package/mingw-byacc.spec, package/pkgsrc/Makefile:
+	bump
+
+2019-06-10  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* config.guess: 2019-06-10
+
+2019-05-22  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* config.sub: 2019-05-22
+
+2018-06-09  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* yacc.1: minor typographical fixes
+
+	* test/btyacc/err_syntax20.tab.c, test/btyacc/error.tab.c, test/btyacc/expr.oxout.tab.c, test/btyacc/grammar.tab.c, test/btyacc/inherit0.tab.c, test/btyacc/inherit1.tab.c, test/btyacc/inherit2.tab.c, test/btyacc/ok_syntax1.tab.c, test/btyacc/pure_calc.tab.c, test/btyacc/pure_error.tab.c, test/btyacc/quote_calc-s.tab.c, test/btyacc/quote_calc.tab.c, test/btyacc/quote_calc2-s.tab.c, test/btyacc/quote_calc2.tab.c, test/btyacc/quote_calc3-s.tab.c, test/btyacc/quote_calc3.tab.c, test/btyacc/quote_calc4-s.tab.c, test/btyacc/quote_calc4.tab.c, test/btyacc/varsyntax_calc1.tab.c, test/btyacc/btyacc_calc1.tab.c, test/btyacc/btyacc_demo.tab.c, test/btyacc/btyacc_destroy1.tab.c, test/btyacc/btyacc_destroy2.tab.c, test/btyacc/btyacc_destroy3.tab.c, test/btyacc/calc.tab.c, test/btyacc/calc1.tab.c, test/btyacc/calc2.tab.c, test/btyacc/calc3.tab.c, test/btyacc/code_calc.code.c, test/btyacc/code_error.code.c, test/btyacc/empty.tab.c, test/btyacc/err_inherit3.tab.c, test/btyacc/err_inherit4.tab.c, test/btyacc/err_syntax10.tab.c, test/btyacc/err_syntax11.tab.c, test/btyacc/err_syntax12.tab.c, test/btyacc/err_syntax18.tab.c, test/btyacc/rename_debug.c, btyaccpar.c:
+	regen
+
+	* VERSION, package/byacc.spec, package/debian/changelog, package/mingw-byacc.spec, package/pkgsrc/Makefile:
+	bump
+
+2018-06-09  Tom.Shields
+
+	* btyaccpar.skel:
+	add casts to fix g++ (clang++) compile errors in the backtracking skeleton
+	due to assignment of ‘void *’ to another pointer type.
+
+2018-05-25  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* test/run_make.sh:
+	check if this is bison 3+ before adding options to suppress warnings
+
+	* package/byacc.spec: build-fix for Mageia 6
+
+	* package/byacc.spec: add btyacc package
+
+	* VERSION, package/byacc.spec, package/debian/changelog, package/mingw-byacc.spec, package/pkgsrc/Makefile:
+	bump
+
+	* package/debian/control: add a package for btyacc
+
+	* package/debian/rules: generate a package for btyacc
+
+2018-05-24  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* test/btyacc/pure_calc.tab.c, test/btyacc/pure_error.tab.c, test/btyacc/quote_calc-s.tab.c, test/btyacc/quote_calc.tab.c, test/btyacc/quote_calc2-s.tab.c, test/btyacc/quote_calc2.tab.c, test/btyacc/quote_calc3-s.tab.c, test/btyacc/quote_calc3.tab.c, test/btyacc/quote_calc4-s.tab.c, test/btyacc/quote_calc4.tab.c, test/btyacc/varsyntax_calc1.tab.c, test/btyacc/code_error.code.c, test/btyacc/empty.tab.c, test/btyacc/err_inherit3.tab.c, test/btyacc/err_inherit4.tab.c, test/btyacc/err_syntax10.tab.c, test/btyacc/err_syntax11.tab.c, test/btyacc/err_syntax12.tab.c, test/btyacc/err_syntax18.tab.c, test/btyacc/err_syntax20.tab.c, test/btyacc/error.tab.c, test/btyacc/expr.oxout.tab.c, test/btyacc/grammar.tab.c, test/btyacc/inherit0.tab.c, test/btyacc/inherit1.tab.c, test/btyacc/inherit2.tab.c, test/btyacc/ok_syntax1.tab.c, btyaccpar.c, test/btyacc/btyacc_calc1.tab.c, test/btyacc/btyacc_demo.tab.c, test/btyacc/btyacc_destroy1.tab.c, test/btyacc/btyacc_destroy2.tab.c, test/btyacc/btyacc_destroy3.tab.c, test/btyacc/calc.tab.c, test/btyacc/calc1.tab.c, test/btyacc/calc2.tab.c, test/btyacc/calc3.tab.c, test/btyacc/code_calc.code.c, test/btyacc/rename_debug.c:
+	regen
+
+	* btyaccpar.skel: fix typo
+
+2018-05-21  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* test/run_make.sh:
+	ignore case for "%" directives to skip with old-yacc, and add %token-table
+	to the list
+
+	* btyaccpar.c: regen
+
+2018-05-21  Christos.Zoulas
+
+	* btyaccpar.skel:
+	improve compatibility with bison by changing the YYLLOC_DEFAULT macro to use
+	YYRHSLOC() macro, and adjusting the array indices of yyerror_loc_range[] for
+	consistency.
+
+2018-05-10  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* output.c:
+	add a fallback definition for YYDEBUG to the -i externs file.
+
+	* test/btyacc/rename_debug.i, test/yacc/rename_debug.i: regen
+
+	* VERSION, package/byacc.spec, package/debian/changelog, package/mingw-byacc.spec, package/pkgsrc/Makefile:
+	bump
+
+2018-05-09  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* configure: regen
+
+	* aclocal.m4: resync with my-autoconf
+
+	* VERSION, package/byacc.spec, package/debian/changelog, package/mingw-byacc.spec, package/pkgsrc/Makefile:
+	bump
+
+	* test/btyacc/rename_debug.i, btyaccpar.c, test/btyacc/btyacc_calc1.tab.c, test/btyacc/btyacc_demo.tab.c, test/btyacc/btyacc_destroy1.tab.c, test/btyacc/btyacc_destroy2.tab.c, test/btyacc/btyacc_destroy3.tab.c, test/btyacc/calc.tab.c, test/btyacc/calc1.tab.c, test/btyacc/calc2.tab.c, test/btyacc/calc3.tab.c, test/btyacc/code_calc.code.c, test/btyacc/code_error.code.c, test/btyacc/empty.tab.c, test/btyacc/err_inherit3.tab.c, test/btyacc/err_inherit4.tab.c, test/btyacc/err_syntax10.tab.c, test/btyacc/err_syntax11.tab.c, test/btyacc/err_syntax12.tab.c, test/btyacc/err_syntax18.tab.c, test/btyacc/err_syntax20.tab.c, test/btyacc/error.tab.c, test/btyacc/expr.oxout.tab.c, test/btyacc/grammar.tab.c, test/btyacc/inherit0.tab.c, test/btyacc/inherit1.tab.c, test/btyacc/inherit2.tab.c, test/btyacc/ok_syntax1.tab.c, test/btyacc/pure_calc.tab.c, test/btyacc/pure_error.tab.c, test/btyacc/quote_calc-s.tab.c, test/btyacc/quote_calc.tab.c, test/btyacc/quote_calc2-s.tab.c, test/btyacc/quote_calc2.tab.c, test/btyacc/quote_calc3-s.tab.c, test/btyacc/quote_calc3.tab.c, test/btyacc/quote_calc4-s.tab.c, test/btyacc/quote_calc4.tab.c, test/btyacc/rename_debug.c, test/btyacc/varsyntax_calc1.tab.c:
+	regen
+
+	* btyaccpar.skel: apply Guy Harris' changes here as well
+
+	* test/btyacc/rename_debug.i, test/yacc/rename_debug.i: regen
+
+	* output.c: correct/improve fallback prototype for yylex()
+
+	* test/btyacc/rename_debug.i, test/yacc/rename_debug.i: regen
+
+2018-05-08  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* test/btyacc/grammar.tab.c, test/yacc/grammar.tab.c: regen
+
+	* test/grammar.y:
+	quiet some warnings from gcc 7 when doing "make check_make"
+
+	* package/debian/watch, package/pkgsrc/Makefile: update ftp-url
+
+	* test/btyacc/ok_syntax1.tab.h, test/btyacc/btyacc_calc1.tab.h: regen
+
+	* output.c:
+	provide yylex() declaration for simple case (request by "Mutiny")
+
+	* test/yacc/err_syntax20.tab.c, test/yacc/error.tab.c, test/yacc/expr.oxout.tab.c, test/yacc/grammar.tab.c, test/yacc/ok_syntax1.tab.c, test/yacc/ok_syntax1.tab.h, test/yacc/pure_calc.tab.c, test/yacc/pure_error.tab.c, test/yacc/quote_calc-s.tab.c, test/yacc/quote_calc.tab.c, test/yacc/quote_calc2-s.tab.c, test/yacc/quote_calc2.tab.c, test/yacc/quote_calc3-s.tab.c, test/yacc/quote_calc3.tab.c, test/yacc/quote_calc4-s.tab.c, test/yacc/quote_calc4.tab.c, test/yacc/varsyntax_calc1.tab.c, test/yacc/calc.tab.c, test/yacc/calc1.tab.c, test/yacc/calc2.tab.c, test/yacc/calc3.tab.c, test/yacc/code_calc.code.c, test/yacc/code_error.code.c, test/yacc/empty.tab.c, test/yacc/err_syntax10.tab.c, test/yacc/err_syntax11.tab.c, test/yacc/err_syntax12.tab.c, test/yacc/err_syntax18.tab.c, test/yacc/rename_debug.c, test/yacc/rename_debug.i, yaccpar.c:
+	regen
+
+	* VERSION, package/byacc.spec, package/debian/changelog, package/debian/copyright, package/mingw-byacc.spec, package/pkgsrc/Makefile:
+	bump
+
+2018-05-06  Guy.Harris
+
+	* yaccpar.skel: two fixes:
+	1) define yydebug only if YYDEBUG is defined and
+	2) make yynerrs a parser-local variable if the parser is reentrant.
+
+2018-02-24  Guy.Harris
+
+	* output.c: do not emit "extern YYSTYPE yylval;" for pure parsers
+
+2018-02-05  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* config.sub: 2018-01-15
+
+	* config.guess: 2018-01-26
+
+2017-12-04  erik.b.andersen
+
+	* main.c: A proper path for temporary files is needed by byacc under
+	Windows commandline, otherwise there's a risk of empty files.
+	The TEMP environment variable is always defined in Windows.
+
+	* defs.h: The noreturn attribute needs to be specified before function
+	to be portable among compilers (gcc, clang, msvc).
+
+2017-12-04  Thomas E. Dickey  <dickey@invisible-island.net>
+
+	* reader.c: adapted fix by Erik B:
+	 a) increase the length of name[] to account for a trailing null
+	 b) note that calling syntax_error() from get_number() does not return
+
+2017-09-14  Tom.Shields
+
+	* yacc.1: fix typo
+
 2017-07-09  Thomas E. Dickey  <dickey@invisible-island.net>
 
 	* package/byacc.spec, package/mingw-byacc.spec:
@@ -2590,7 +2833,7 @@
 
 	* vmsbuild.com: original version
 
-2000-02-23  dickey@clark.net
+2000-02-23  Thomas E. Dickey  <dickey@clark.net>
 
 	* test/RCS, RCS: PERMIT FILE
 
@@ -2629,7 +2872,7 @@
 
 	* test/ftp.output, test/ftp.tab.c, test/ftp.tab.h: RCS_BASE
 
-1993-02-22  Thomas E. Dickey  <dickey@software.org>
+1993-02-22  dickey@software.org
 
 	* test/yacc/error.output, test/yacc/error.tab.h:
 	reference output for testing
@@ -2669,7 +2912,7 @@
 
 	* symtab.c, lalr.c, error.c: original version
 
-1990-01-16  Thomas E. Dickey  <dickey@software.org>
+1990-01-16  dickey@software.org
 
 	* test/code_error.y, test/pure_error.y: RCS_BASE
 
diff --git a/contrib/byacc/VERSION b/contrib/byacc/VERSION
index a86b7c7956..17c628b73f 100644
--- a/contrib/byacc/VERSION
+++ b/contrib/byacc/VERSION
@@ -1 +1 @@
-20170709
+20190617
diff --git a/contrib/byacc/defs.h b/contrib/byacc/defs.h
index eac530515e..f7c449cc1d 100644
--- a/contrib/byacc/defs.h
+++ b/contrib/byacc/defs.h
@@ -1,4 +1,4 @@
-/* $Id: defs.h,v 1.59 2017/07/09 18:12:46 tom Exp $ */
+/* $Id: defs.h,v 1.61 2019/06/16 15:07:51 tom Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -274,6 +274,7 @@ struct param
 
 /* global variables */
 
+extern char dflag2;
 extern char dflag;
 extern char gflag;
 extern char iflag;
@@ -413,6 +414,21 @@ extern param *parse_param;
 #endif
 #endif
 
+#ifdef __GNUC__
+#define ATTRIBUTE_NORETURN __attribute__((noreturn))
+#elif defined(_MSC_VER)
+#define ATTRIBUTE_NORETURN __declspec(noreturn)
+#else
+#define ATTRIBUTE_NORETURN
+#endif
+
+#if defined(NDEBUG) && defined(_MSC_VER)
+#define NODEFAULT   __assume(0);
+#else
+#define NODEFAULT
+#endif
+#define NOTREACHED	NODEFAULT
+
 #ifndef GCC_UNUSED
 #if defined(__unused)
 #define GCC_UNUSED		__unused
@@ -440,20 +456,31 @@ struct ainfo
 
 extern void arg_number_disagree_warning(int a_lineno, char *a_name);
 extern void arg_type_disagree_warning(int a_lineno, int i, char *a_name);
+ATTRIBUTE_NORETURN
 extern void at_error(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
 extern void at_warning(int a_lineno, int i);
+ATTRIBUTE_NORETURN
 extern void bad_formals(void) GCC_NORETURN;
 extern void default_action_warning(char *s);
 extern void destructor_redeclared_warning(const struct ainfo *);
+ATTRIBUTE_NORETURN
 extern void dollar_error(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
 extern void dollar_warning(int a_lineno, int i);
+ATTRIBUTE_NORETURN
 extern void fatal(const char *msg) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void illegal_character(char *c_cptr) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void missing_brace(void) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void no_grammar(void) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void no_space(void) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void open_error(const char *filename) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void over_unionized(char *u_cptr) GCC_NORETURN;
 extern void prec_redeclared(void);
 extern void reprec_warning(char *s);
@@ -461,25 +488,43 @@ extern void restarted_warning(void);
 extern void retyped_warning(char *s);
 extern void revalued_warning(char *s);
 extern void start_requires_args(char *a_name);
+ATTRIBUTE_NORETURN
 extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void terminal_lhs(int s_lineno) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void terminal_start(char *s) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void tokenized_start(char *s) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void undefined_goal(char *s) GCC_NORETURN;
 extern void undefined_symbol_warning(char *s);
+ATTRIBUTE_NORETURN
 extern void unexpected_EOF(void) GCC_NORETURN;
-extern void unknown_arg_warning(int d_lineno, const char *dlr_opt, const char *d_arg, const char *d_line, const char *d_cptr);
+extern void unknown_arg_warning(int d_lineno, const char *dlr_opt,
+				const char *d_arg, const char *d_line,
+				const char *d_cptr);
+ATTRIBUTE_NORETURN
 extern void unknown_rhs(int i) GCC_NORETURN;
 extern void unsupported_flag_warning(const char *flag, const char *details);
+ATTRIBUTE_NORETURN
 extern void unterminated_action(const struct ainfo *) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void unterminated_comment(const struct ainfo *) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void unterminated_string(const struct ainfo *) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void unterminated_text(const struct ainfo *) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void unterminated_union(const struct ainfo *) GCC_NORETURN;
 extern void untyped_arg_warning(int a_lineno, const char *dlr_opt, const char *a_name);
+ATTRIBUTE_NORETURN
 extern void untyped_lhs(void) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void untyped_rhs(int i, char *s) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void used_reserved(char *s) GCC_NORETURN;
+ATTRIBUTE_NORETURN
 extern void unterminated_arglist(const struct ainfo *) GCC_NORETURN;
 extern void wrong_number_args_warning(const char *which, const char *a_name);
 extern void wrong_type_for_arg_warning(int i, char *a_name);
@@ -499,6 +544,7 @@ extern void show_shifts(void);
 
 /* main.c */
 extern void *allocate(size_t n);
+ATTRIBUTE_NORETURN
 extern void done(int k) GCC_NORETURN;
 
 /* mkpar.c */
diff --git a/contrib/byacc/main.c b/contrib/byacc/main.c
index 9a8099c5ec..5dc2ccc855 100644
--- a/contrib/byacc/main.c
+++ b/contrib/byacc/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.60 2017/04/30 20:57:56 Julien.Ramseier Exp $ */
+/* $Id: main.c,v 1.65 2019/06/16 19:59:58 tom Exp $ */
 
 #include <signal.h>
 #ifndef _WIN32
@@ -33,6 +33,7 @@ static MY_TMPFILES *my_tmpfiles;
 #endif /* USE_MKSTEMP */
 
 char dflag;
+char dflag2;
 char gflag;
 char iflag;
 char lflag;
@@ -150,7 +151,7 @@ done(int k)
     if (rflag)
 	DO_FREE(code_file_name);
 
-    if (dflag)
+    if (dflag && !dflag2)
 	DO_FREE(defines_file_name);
 
     if (iflag)
@@ -210,6 +211,7 @@ usage(void)
 	,"  -b file_prefix        set filename prefix (default \"y.\")"
 	,"  -B                    create a backtracking parser"
 	,"  -d                    write definitions (" DEFINES_SUFFIX ")"
+	,"  -H defines_file       write definitions to defines_file"
 	,"  -i                    write interface (y.tab.i)"
 	,"  -g                    write a graphical description"
 	,"  -l                    suppress #line directives"
@@ -230,7 +232,7 @@ usage(void)
     for (n = 0; n < sizeof(msg) / sizeof(msg[0]); ++n)
 	fprintf(stderr, "%s\n", msg[n]);
 
-    exit(1);
+    exit(EXIT_FAILURE);
 }
 
 static void
@@ -248,6 +250,7 @@ setflag(int ch)
 
     case 'd':
 	dflag = 1;
+	dflag2 = 0;
 	break;
 
     case 'g':
@@ -340,6 +343,16 @@ getargs(int argc, char *argv[])
 		usage();
 	    continue;
 
+	case 'H':
+	    dflag = dflag2 = 1;
+	    if (*++s)
+		defines_file_name = s;
+	    else if (++i < argc)
+		defines_file_name = argv[i];
+	    else
+		usage();
+	    continue;
+
 	case 'o':
 	    if (*++s)
 		output_file_name = s;
@@ -476,7 +489,7 @@ create_file_names(void)
     else
 	code_file_name = output_file_name;
 
-    if (dflag)
+    if (dflag && !dflag2)
     {
 	CREATE_FILE_NAME(defines_file_name, defines_suffix);
     }
@@ -578,7 +591,8 @@ open_tmpfile(const char *label)
     char *name;
     const char *mark;
 
-    if ((tmpdir = getenv("TMPDIR")) == 0 || access(tmpdir, W_OK) != 0)
+    if (((tmpdir = getenv("TMPDIR")) == 0 || access(tmpdir, W_OK) != 0) ||
+	((tmpdir = getenv("TEMP")) == 0 || access(tmpdir, W_OK) != 0))
     {
 #ifdef P_tmpdir
 	tmpdir = P_tmpdir;
@@ -678,7 +692,7 @@ open_files(void)
 	fprintf(graph_file, "\t*/\n");
     }
 
-    if (dflag)
+    if (dflag || dflag2)
     {
 	defines_file = fopen(defines_file_name, "w");
 	if (defines_file == 0)
diff --git a/contrib/byacc/output.c b/contrib/byacc/output.c
index 9f87911d80..f7352dc2f5 100644
--- a/contrib/byacc/output.c
+++ b/contrib/byacc/output.c
@@ -1,4 +1,4 @@
-/* $Id: output.c,v 1.83 2017/07/09 18:13:42 tom Exp $ */
+/* $Id: output.c,v 1.87 2018/05/10 09:08:46 tom Exp $ */
 
 #include "defs.h"
 
@@ -1259,7 +1259,8 @@ output_defines(FILE * fp)
 		while ((c = getc(union_file)) != EOF)
 		    putc_code(fp, c);
 	    }
-	    fprintf(fp, "extern YYSTYPE %slval;\n", symbol_prefix);
+	    if (!pure_parser)
+		fprintf(fp, "extern YYSTYPE %slval;\n", symbol_prefix);
 	}
 #if defined(YYBTYACC)
 	if (locations)
@@ -1288,6 +1289,15 @@ output_stored_text(FILE * fp)
     write_code_lineno(fp);
 }
 
+static int
+output_yydebug(FILE * fp)
+{
+    fprintf(fp, "#ifndef YYDEBUG\n");
+    fprintf(fp, "#define YYDEBUG %d\n", tflag);
+    fprintf(fp, "#endif\n");
+    return 3;
+}
+
 static void
 output_debug(void)
 {
@@ -1298,16 +1308,11 @@ output_debug(void)
     ++outline;
     fprintf(code_file, "#define YYFINAL %d\n", final_state);
 
-    putl_code(code_file, "#ifndef YYDEBUG\n");
-    ++outline;
-    fprintf(code_file, "#define YYDEBUG %d\n", tflag);
-    putl_code(code_file, "#endif\n");
+    outline += output_yydebug(code_file);
 
     if (rflag)
     {
-	fprintf(output_file, "#ifndef YYDEBUG\n");
-	fprintf(output_file, "#define YYDEBUG %d\n", tflag);
-	fprintf(output_file, "#endif\n");
+	output_yydebug(output_file);
     }
 
     maxtok = 0;
@@ -1793,6 +1798,23 @@ output_lex_decl(FILE * fp)
 	putl_code(fp, "# define YYLEX yylex()\n");
     }
     putl_code(fp, "#endif\n");
+
+    /*
+     * Provide a prototype for yylex for the simplest case.  This is done for
+     * better compatibility with older yacc's, but can be a problem if someone
+     * uses "static int yylex(void);"
+     */
+    if (!pure_parser
+#if defined(YYBTYACC)
+	&& !backtrack
+#endif
+	&& !strcmp(symbol_prefix, "yy"))
+    {
+	putl_code(fp, "\n");
+	putl_code(fp, "#if !(defined(yylex) || defined(YYSTATE))\n");
+	putl_code(fp, "int YYLEX_DECL();\n");
+	putl_code(fp, "#endif\n");
+    }
 }
 
 static void
@@ -2021,6 +2043,8 @@ output(void)
 
     if (iflag)
     {
+	fprintf(externs_file, "\n");
+	output_yydebug(externs_file);
 	output_externs(externs_file, global_vars);
 	if (!pure_parser)
 	    output_externs(externs_file, impure_vars);
diff --git a/contrib/byacc/reader.c b/contrib/byacc/reader.c
index ebf40d2a6d..21303577aa 100644
--- a/contrib/byacc/reader.c
+++ b/contrib/byacc/reader.c
@@ -1,4 +1,4 @@
-/* $Id: reader.c,v 1.73 2017/07/09 19:15:35 tom Exp $ */
+/* $Id: reader.c,v 1.74 2017/12/04 17:50:02 tom Exp $ */
 
 #include "defs.h"
 
@@ -437,7 +437,7 @@ nextc(void)
 /* *INDENT-OFF* */
 static struct keyword
 {
-    char name[14];
+    char name[16];
     int token;
 }
 keywords[] = {
@@ -1353,8 +1353,7 @@ get_number(void)
 	if (n > MAXYYINT)
 	{
 	    syntax_error(lineno, line, base);
-	    n = 0;
-	    break;
+	    /*NOTREACHED */
 	}
     }
 
diff --git a/contrib/byacc/yacc.1 b/contrib/byacc/yacc.1
index 8076ab03b3..9f74bb547d 100644
--- a/contrib/byacc/yacc.1
+++ b/contrib/byacc/yacc.1
@@ -1,16 +1,19 @@
-.\" $Id: yacc.1,v 1.24 2014/10/06 00:03:48 tom Exp $
+.\" $Id: yacc.1,v 1.29 2019/06/16 19:58:03 tom Exp $
 .\"
 .\" .TH YACC 1 "July\ 15,\ 1990"
 .\" .UC 6
-.de ES
-.ne 8
+.ds N Yacc
+.ds n yacc
+.de Ex
+.RS +7
+.PP
 .nf
-.sp
-.in +4
+.ft CW
 ..
-.de XE
-.in -4
+.de Ee
 .fi
+.ft R
+.RE
 ..
 .\" Escape single quotes in literal strings from groff's Unicode transform.
 .ie \n(.g .ds AQ \(aq
@@ -21,14 +24,17 @@
 .el       .ds '' ''
 .\" Bulleted paragraph
 .de bP
-.IP \(bu 4
+.ie n  .IP \(bu 4
+.el    .IP \(bu 2
 ..
-.TH YACC 1 "October 5, 2014" "Berkeley Yacc" "User Commands"
+.TH YACC 1 "June 16, 2019" "Berkeley Yacc" "User Commands"
 .SH NAME
-Yacc \- an LALR(1) parser generator
+\*N \- an LALR(1) parser generator
 .SH SYNOPSIS
-.B yacc [ -BdgilLPrtvVy ] [ \-b
+.B \*n [ -BdgilLPrtvVy ] [ \-b
 .I file_prefix
+.B ] [ \-H
+.I defines_file
 .B ] [ \-o
 .I output_file
 .B ] [ \-p
@@ -36,15 +42,15 @@ Yacc \- an LALR(1) parser generator
 .B ]
 .I filename
 .SH DESCRIPTION
-.B Yacc
+.B \*N
 reads the grammar specification in the file
 .I filename
 and generates an LALR(1) parser for it.
 The parsers consist of a set of LALR(1) parsing tables and a driver routine
 written in the C programming language.
-.B Yacc
+.B \*N
 normally writes the parse tables and the driver routine to the file
-.IR y.tab.c.
+.I y.tab.c.
 .PP
 The following options are available:
 .TP 5
@@ -53,30 +59,35 @@ The
 .B \-b
 option changes the prefix prepended to the output file names to
 the string denoted by
-.IR file_prefix.
+.I file_prefix.
 The default prefix is the character
-.IR y.
+.I y.
 .TP
 .B \-B
-create a backtracking parser (compile-type configuration for \fBbtyacc\fP).
+create a backtracking parser (compile-time configuration for \fBbtyacc\fP).
 .TP
 .B \-d
-The \fB-d\fR option causes the header file
-.BR y.tab.h
+causes the header file
+.B y.tab.h
 to be written.
 It contains #define's for the token identifiers.
 .TP
+\fB\-H \fP\fIdefines_file\fR
+causes #define's for the token identifiers
+to be written to the given \fIdefines_file\fP rather
+than the \fBy.tab.h\fP file used by the \fB\-d\fP option.
+.TP
 .B \-g
 The
 .B \-g
 option causes a graphical description of the generated LALR(1) parser to
 be written to the file
-.BR y.dot
+.B y.dot
 in graphviz format, ready to be processed by dot(1).
 .TP
 .B \-i
 The \fB-i\fR option causes a supplementary header file
-.BR y.tab.i
+.B y.tab.i
 to be written.
 It contains extern declarations
 and supplementary #define's as needed to map the conventional \fIyacc\fP
@@ -92,17 +103,18 @@ of lex- and yacc-files.
 If the
 .B \-l
 option is not specified,
-.B yacc
+.B \*n
 will insert \fI#line\fP directives in the generated code.
 The \fI#line\fP directives let the C compiler relate errors in the
 generated code to the user's original code.
 If the \fB-l\fR option is specified,
-.B yacc
+.B \*n
 will not insert the \fI#line\fP directives.
 \&\fI#line\fP directives specified by the user will be retained.
 .TP
 .B \-L
-enable position processing, e.g., \*(``%locations\*('' (compile-type configuration for \fBbtyacc\fP).
+enable position processing,
+e.g., \*(``%locations\*('' (compile-time configuration for \fBbtyacc\fP).
 .TP
 \fB\-o \fP\fIoutput_file\fR
 specify the filename for the parser file.
@@ -115,9 +127,9 @@ The
 .B \-p
 option changes the prefix prepended to yacc-generated symbols to
 the string denoted by
-.IR symbol_prefix.
+.I symbol_prefix.
 The default prefix is the string
-.BR yy.
+.B yy.
 .TP
 .B \-P
 create a reentrant parser, e.g., \*(``%pure-parser\*(''.
@@ -126,12 +138,12 @@ create a reentrant parser, e.g., \*(``%pure-parser\*(''.
 The
 .B \-r
 option causes
-.B yacc
+.B \*n
 to produce separate files for code and tables.
 The code file is named
-.IR y.code.c,
+.I y.code.c,
 and the tables file is named
-.IR y.tab.c.
+.I y.tab.c.
 The prefix \*(``\fIy.\fP\*('' can be overridden using the \fB\-b\fP option.
 .TP
 .B \-s
@@ -140,19 +152,19 @@ a \*(``\fB%token\fP\*('' statement,
 to more closely match original \fByacc\fP behavior.
 .IP
 Normally when \fByacc\fP sees a line such as
-.ES
+.Ex
 %token OP_ADD "ADD"
-.XE
+.Ee
 .IP
 it notices that the quoted \*(``ADD\*('' is a valid C identifier,
 and generates a #define not only for OP_ADD,
 but for ADD as well,
 e.g.,
-.ES
+.Ex
 #define OP_ADD 257
 .br
 #define ADD 258
-.XE
+.Ee
 .IP
 The original \fByacc\fP does not generate the second \*(``\fB#define\fP\*(''.
 The \fB\-s\fP option suppresses this \*(``\fB#define\fP\*(''.
@@ -165,7 +177,7 @@ though original \fByacc\fP and bison also accept string literals.
 The
 .B \-t
 option changes the preprocessor directives generated by
-.B yacc
+.B \*n
 so that debugging statements will be incorporated in the compiled code.
 .TP
 .B \-v
@@ -173,7 +185,7 @@ The
 .B \-v
 option causes a human-readable description of the generated parser to
 be written to the file
-.IR y.output.
+.I y.output.
 .TP
 .B \-V
 print the version number to the standard output.
@@ -181,8 +193,14 @@ print the version number to the standard output.
 .B \-y
 \fByacc\fP ignores this option,
 which bison supports for ostensible POSIX compatibility.
+.PP
+The \fIfilename\fP parameter is not optional.
+However, \fByacc\fP accepts a single \*(``\-\*('' to read the grammar
+from the standard input.
+A double \*(``\-\-\*('' marker denotes the end of options.
+A single \fIfilename\fP parameter is expected after a \*(``\-\-\*('' marker.
 .SH EXTENSIONS
-.B yacc
+.B \*N
 provides some extensions for
 compatibility with bison and other implementations of yacc.
 The \fB%destructor\fP and \fB%locations\fP features are available
@@ -206,7 +224,8 @@ if the \fBYYSTYPE\fP value is, or contains,
 pointers to dynamically allocated memory.
 .IP
 The bracketed \fIcode\fP is invoked whenever the parser discards one of
-the symbols. Within \fIcode\fP, \*(``\fB$$\fP\*('' or
+the symbols.
+Within \fIcode\fP, \*(``\fB$$\fP\*('' or
 \*(``\fB$<tag>$\fP\*('' designates the semantic value associated with the
 discarded symbol, and  \*(``\fB@$\fP\*('' designates its location (see
 \fB%locations\fP directive).
@@ -248,21 +267,23 @@ similar to management of semantic value information provided in \fByylval\fP.
 As for semantic values, locations can be referenced within actions using
 \fB@$\fP to refer to the location of the left hand side symbol, and \fB@N\fP
 (\fBN\fP an integer) to refer to the location of one of the right hand side
-symbols. Also as for semantic values, when a rule is matched, a default
+symbols.
+Also as for semantic values, when a rule is matched, a default
 action is used the compute the location represented by \fB@$\fP as the
 beginning of the first symbol and the end of the last symbol in the right
-hand side of the rule. This default computation can be overridden by
+hand side of the rule.
+This default computation can be overridden by
 explicit assignment to \fB@$\fP in a rule action.
 .IP
 The type of \fByylloc\fP is \fBYYLTYPE\fP, which is defined by default as:
-.ES
+.Ex
 typedef struct YYLTYPE {
     int first_line;
     int first_column;
     int last_line;
     int last_column;
 } YYLTYPE;
-.XE
+.Ee
 .IP
 \fBYYLTYPE\fP can be redefined by the user
 (\fBYYLTYPE_IS_DEFINED\fP must be defined, to inhibit the default)
@@ -292,23 +313,24 @@ reentrant.
 \fB %token-table\fP
 Make the parser's names for tokens available in the \fByytname\fP array.
 However,
-.B yacc
+.B \*n
 does not predefine \*(``$end\*('', \*(``$error\*(''
 or \*(``$undefined\*('' in this array.
 .SH PORTABILITY
 According to Robert Corbett,
-.ES
-    Berkeley Yacc is an LALR(1) parser generator.  Berkeley Yacc has been made
-as compatible as possible with AT&T Yacc.  Berkeley Yacc can accept any input
-specification that conforms to the AT&T Yacc documentation.  Specifications
-that take advantage of undocumented features of AT&T Yacc will probably be
-rejected.
-.XE
+.Ex
+Berkeley Yacc is an LALR(1) parser generator.  Berkeley Yacc
+has been made as compatible as possible with AT&T Yacc. 
+Berkeley Yacc can accept any input specification that
+conforms to the AT&T Yacc documentation.  Specifications
+that take advantage of undocumented features of AT&T Yacc
+will probably be rejected.
+.Ee
 .PP
 The rationale in
-.ES
+.Ex
 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/yacc.html
-.XE
+.Ee
 .PP
 documents some features of AT&T yacc which are no longer required for POSIX
 compliance.
@@ -320,12 +342,12 @@ Here are a few differences:
 .bP
 \fBYacc\fP accepts an equals mark preceding the left curly brace
 of an action (as in the original grammar file \fBftp.y\fP):
-.ES
-	|	STAT CRLF
-		= {
-			statcmd();
-		}
-.XE
+.Ex
+    |   STAT CRLF
+        = {
+                statcmd();
+        }
+.Ee
 .bP
 \fBYacc\fP and bison emit code in different order, and in particular bison
 makes forward reference to common functions such as yylex, yyparse and
@@ -340,12 +362,12 @@ relying on directives embedded in the grammar file.
 Bison's \*(``\fB\-y\fP\*('' option does not affect bison's lack of support for
 features of AT&T yacc which were deemed obsolescent.
 .bP
-\fBYacc\fP accepts multiple parameters with \fB%lex-param\fP and \fB%parse-param\fP
-in two forms
-.ES
+\fBYacc\fP accepts multiple parameters
+with \fB%lex-param\fP and \fB%parse-param\fP in two forms
+.Ex
 {type1 name1} {type2 name2} ...
 {type1 name1,  type2 name2 ...}
-.XE
+.Ee
 .IP
 Bison accepts the latter (though undocumented), but depending on the
 release may generate bad code.
diff --git a/contrib/byacc/yaccpar.c b/contrib/byacc/yaccpar.c
index 6186453019..e57bd4bb7d 100644
--- a/contrib/byacc/yaccpar.c
+++ b/contrib/byacc/yaccpar.c
@@ -2,7 +2,7 @@
  * @Id: skel2c,v 1.4 2016/06/07 00:26:09 tom Exp @
  */
 
-/* @Id: yaccpar.skel,v 1.8 2016/12/02 21:44:42 tom Exp @ */
+/* @Id: yaccpar.skel,v 1.10 2018/05/06 21:28:14 Guy.Harris Exp @ */
 
 #include "defs.h"
 
@@ -67,8 +67,9 @@ const char *const tables[] =
 const char *const global_vars[] =
 {
     "",
+    "#if YYDEBUG",
     "int      yydebug;",
-    "int      yynerrs;",
+    "#endif",
     0
 };
 
@@ -79,6 +80,7 @@ const char *const impure_vars[] =
     "int      yychar;",
     "YYSTYPE  yyval;",
     "YYSTYPE  yylval;",
+    "int      yynerrs;",
     0
 };
 
@@ -124,6 +126,7 @@ const char *const body_vars[] =
     "    int      yychar;",
     "    YYSTYPE  yyval;",
     "    YYSTYPE  yylval;",
+    "    int      yynerrs;",
     "",
     "    /* variables for the parser stack */",
     "    YYSTACKDATA yystack;",
-- 
2.23.0

