Compare commits

...
89 Commits
Author SHA1 Message Date
Akim Demaille 1505e8bb78 version 2.6
* NEWS: Record release date.
2012-07-19 15:24:23 +02:00
Akim Demaille 58c7e5ee2c maint: prepare for release 2.6
* NEWS: here.
2012-07-19 15:21:32 +02:00
Akim Demaille ad6b775fc5 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2012-07-18 18:33:25 +02:00
Akim Demaille 5d614dfa8c version 2.5.91
* NEWS: Record release date.
2012-07-18 18:19:32 +02:00
Akim Demaille 858c700fc0 maint: prepare NEWS. 2012-07-18 18:19:12 +02:00
Akim Demaille c30717cafa maint: fix spaces.
* build-aux/Makefile.am: here.
2012-07-18 17:56:30 +02:00
Akim Demaille 0e98a81e00 tests: adjust to case where the C compiler is actually a C++ compiler
* tests/atlocal.in (CC_IS_CXX): New.
* tests/headers.at (Several parsers): Use it.
2012-07-18 09:17:31 +02:00
Akim Demaille d5c20d1a36 tests: fix dependencies
* tests/Makefile.am: we need atconfig and atlocal to be up to date
when calling testsuite.
2012-07-18 09:17:31 +02:00
Akim Demaille e6ae99fe75 doc: fix Texinfo command
* doc/bison.texi: In parens, use @pxref.
2012-07-18 09:17:31 +02:00
Akim Demaille bcbbf65486 maint: Valgrind on OS X.
* configure.ac (VALGRIND_PREBISON): New.
* tests/Makefile.am (maintainer-check-valgrind): Use it.
* etc/darwin11.4.0.supp: New.
* configure.ac, etc/Makefile.am: Use it.
* configure.ac: Disable Valgrind on Mac OS X.
* README-hacking: Explain why.
2012-07-18 09:17:15 +02:00
Akim Demaille 1aa9fa823b tests: be sure that backups are safe.
* tests/local.at (at_save_special_files): here.
2012-07-17 14:47:35 +02:00
Akim Demaille 321b8117a6 maint: dead comment.
* etc/README: here.
2012-07-17 14:47:35 +02:00
Akim Demaille e4828e2384 tests: refactor for legibility.
* tests/local.at (AT_BISON_CHECK_WARNINGS, AT_BISON_CHECK_WARNINGS_):
New.
2012-07-17 14:47:34 +02:00
Akim Demaille a122efad8a tests: refactor the bison invocations.
* tests/local.at (m4_null_if, AT_BISON_CHECK_): New.
2012-07-17 14:47:34 +02:00
Akim Demaille 15ffba51b0 maint: fix syntax-check ignore patterns.
* cfg.mk: here.
2012-07-17 12:14:55 +02:00
Akim Demaille ea6a2d96db gnulib: update 2012-07-17 09:49:57 +02:00
Akim Demaille ae63f0e8e2 gnulib: update.
* gnulib: Update so that gitlog-to-changelog support --srcdir.
* Makefile.am: Use it.
2012-07-16 20:40:18 +02:00
Akim Demaille 41c11ce484 gnulib: update
* bootstrap, build-aux/.gitignore, gnulib, m4/.gitignore: update.
2012-07-10 16:07:32 +02:00
Akim Demaille a59a6ddef4 maint: update release instructions
* README-hacking: here.
2012-07-06 10:21:39 +02:00
Akim Demaille aca4ddc75d maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2012-07-05 16:29:06 +02:00
Akim Demaille 47977a7e74 version 2.5.90
* NEWS: Record release date.
2012-07-05 16:20:44 +02:00
Akim Demaille 813f7d3482 build: fix gen-ChangeLog call.
* Makefile.am: Be sure to catch errors, and fix option name
2012-07-05 16:16:10 +02:00
Akim Demaille 7a9e6d65ea gnulib: update.
* gnulib/build-aux/do-release-commit-and-tag: Fix.
2012-07-05 15:24:34 +02:00
Akim Demaille 916f26b65a tests: fix SKIP_IF for Java.
* tests/local.at (AT_JAVA_COMPILE): here.
2012-07-05 14:27:09 +02:00
Akim Demaille 32ae07efde api.prefix: incompatible with %name-prefix.
* data/bison.m4: Make it incompatible.
* tests/input.at: Check that it is.
2012-07-05 12:41:16 +02:00
Akim Demaille ad60e80f3d api.prefix: strengthen the tests and fix push-parsers.
* tests/calc.at: Check api.prefix in addition to %name-prefix.
* tests/headers.at: Check push parsers and pure interface.
* tests/local.at: Use YYLTYPE renamed.
* data/yacc.c (b4_declare_yyparse_push_): Handle api.prefix.
* doc/bison.texi: Style changes.
2012-07-05 12:41:15 +02:00
Akim Demaille 2a824fae30 skeletons: style changes.
* data/bison.m4: Define default values after having defined
the support macros.
Kill a dead comment.
2012-07-05 12:41:09 +02:00
Akim Demaille c242519127 NEWS: minor changes.
* NEWS: style changes.
2012-07-05 12:41:09 +02:00
Akim Demaille e358222ba8 api.prefix: improve the documentation for YYDEBUG.
* doc/bison.texi: Explain how api.prefix is applied to YYDEBUG.
2012-07-05 12:41:08 +02:00
Akim Demaille 9dcb193aeb gnulib: update.
* bootstrap, gnulib: Update.
* cfg.mk (syntax-check): Don't check "error" usage in bison.texi.
2012-07-05 11:13:47 +02:00
Akim Demaille faff3bef5b tests: headers.at: strengthen.
* tests/headers.at (Several headers): Be stricter when checking
the exported macros.
2012-07-04 12:24:13 +02:00
Akim Demaille 53ab797db7 glr.cc: do not override C++ definitions by C macros.
* data/glr.c: here.
* data/glr.cc: Fix overquotation.
* tests/headers.at: Comment changes.
2012-07-04 12:24:13 +02:00
Akim Demaille 426903aa75 YYLLOC_DEFAULT: factor, and don't export it in headers.
* data/c++.m4, data/c.m4 (b4_yylloc_default_define): New.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c: Use it.
* data/glr.cc: Do not define YYLLOC_DEFAULT in the header file,
but in the implementation one.
2012-07-04 12:24:13 +02:00
Akim Demaille 9104636b03 api.prefix: do not use #define to handle YYSTYPE_IS_TRIVIAL etc.
The following mixture is insane:

  #define YYSTYPE_IS_TRIVIAL PREFIX_STYPE_IS_TRIVIAL
  #if (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)

since, of course YYSTYPE_IS_TRIVIAL is defined.  Instead we could
define YYSTYPE_IS_TRIVIAL as PREFIX_STYPE_IS_TRIVIAL only when the
later is defined, but let's avoid stacking CPP on top of M4: rather, use

  #if (defined PREFIX_STYPE_IS_TRIVIAL && PREFIX_STYPE_IS_TRIVIAL)

* data/glr.c, data/yacc.c: Use YYSTYPE_IS_TRIVIAL, YYSTYPE_IS_DECLARED,
YYLTYPE_IS_TRIVIAL and YYLTYPE_IS_DECLARED under their api.prefix-renamed
name.
2012-07-04 12:24:13 +02:00
Akim Demaille 1168b32295 tests: portability fixes.
Reported by Hydra.

* tests/headers.at (Several headers): Be sure to include config.h
in the files to compile.
2012-07-04 12:24:13 +02:00
Akim Demaille 771dc64324 c++: fewer #includes in the headers.
* data/lalr1.cc: Define YY_NULL in the *.cc file, it is not needed
in the header.
* data/location.cc: iosfwd suffices.
2012-07-04 12:24:13 +02:00
Akim Demaille a7385a21ce glr.cc: formatting changes.
* data/glr.cc: here.
2012-07-04 12:24:13 +02:00
Akim Demaille b142cfd128 tests: more logs.
* tests/headers.at (Several parsers): Here.
2012-07-04 12:24:13 +02:00
Akim Demaille 5f108727a1 api.prefix: also rename YYDEBUG.
The testsuite in master has shown weird errors for the "Mulitple
Parsers" tests: the caller of p5.parse() received some apparently
random value, while tracing p5.parse() showed that the function was
consistently returning 0.

It happens when mixing several parser headers, some generated without
%debug, others with.  In particular the C++ parser was generated with
%debug, i.e., with:

  #ifndef YYDEBUG
  # define YYDEBUG 1
  #endif

and compiled separatedly.  Yet, its header was included after the one
of another parser, this time without %debug, i.e., with

  #ifndef YYDEBUG
  # define YYDEBUG 0
  #endif

in its header.  As a result, the parser was compiled with YYDEBUG set,
but its header was used without.  Since the layout of the objects are
then completely different, boom.

Therefore, do not change the value of YYDEBUG.  Rather, use it as a
default value for <API.PREFIX>DEBUG.

* data/c.m4 (b4_YYDEBUG_define): New.
(b4_declare_yydebug): Rename as...
(b4_yydebug_declare): this, for consistency.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c: Use it.
* NEWS: Document it.
2012-07-04 12:24:12 +02:00
Akim Demaille 242cc08e8d NEWS: spell check.
* NEWS: here.
2012-07-02 09:26:22 +02:00
Akim Demaille 4b3847c3c0 api.prefix.
* data/c.m4 (b4_api_prefix, b4_api_PREFIX): New.
(b4_prefix, b4_union_name, b4_token_enums, b4_declare_yylstype): Use them.
* data/glr.c, data/yacc.c, data/glr.cc, data/lalr1.cc: Use them to change
the prefix of exported preprocessor symbols.
* src/getargs.c (usage): Ditto.
* tests/headers.at (Several parsers): New.
* tests/local.at (AT_API_PREFIX): New.
AT_YYSTYPE, AT_YYLTYPE): Adjust.
* doc/bison.texi (Multiple Parsers): Move documentation of %name-prefix to...
(Table of Symbols): here.
(Multiple Parsers): Document api.prefix.
(%define Summary): Point to it.
Use @code for variable names.
(Bison Options): -p/--name-prefix are obsoleted.
* NEWS: Announce api.prefix.
2012-06-29 17:40:42 +02:00
Akim Demaille 087dcd7868 tests: use the generalized default yylex.
* tests/actions.at, tests/glr-regression.at, tests/regression.at: here.
2012-06-28 15:01:36 +02:00
Akim Demaille 95361618de tests: AT_YYERROR_DEFINE: prepare for list of ints.
* tests/local.at (AT_YYERROR_DEFINE): Don't add quotes, check their
presence to detect char/int types.
* tests/actions.at, tests/conflicts.at, tests/glr-regression.at,
* tests/push.at, tests/regression.at: Adjust.
2012-06-28 15:01:36 +02:00
Akim Demaille 694af10cb7 skeletons: no longer define YYLSP_NEEDED.
* data/c.m4, data/glr.cc: here.
* NEWS, TODO: Adjust.
2012-06-27 10:03:23 +02:00
Akim Demaille 258cddbc36 c++: do not export YYTOKEN_TABLE and YYERROR_VERBOSE.
* src/output.c (prepare_symbols): Do not define b4_token_table.
(prepare): Define b4_token_table_flag.
* data/bison.m4 (b4_token_table_if): New.
Arm it when error-verbose.
* data/glr.c, data/yacc.c (YYTOKEN_TABLE): Remove.
Use m4.
* data/lalr1.cc: Likewise.
(YYERROR_VERBOSE): Remove.
* NEWS, doc/bison.texi: Document this.
2012-06-27 10:03:21 +02:00
Akim Demaille 9bcffa0c13 maint: use *.texi.
This is more consistent with the other packages, and Automake-NG
supports only *.texi.

* doc/bison.texinfo: Rename as...
* doc/bison.texi: this.
* doc/Makefile.am, examples/calc++/Makefile.am: Adjust.
2012-06-26 16:55:23 +02:00
Akim Demaille a32a2d57a5 tests: do not output m4 set up.
* tests/local.at (AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS):
Use a diversion to avoid outputting comments etc.
Removes 17k lines from testsuite (10% of the number of lines).
2012-06-26 14:07:34 +02:00
Akim Demaille 8d6c1b5e85 tests: use the generic yyerror function.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Factor.
Use AT_YYERROR_DEFINE.
Therefore, instead of using stdout, use and check stderr.
* tests/glr-regression.at (Uninitialized location when reporting ambiguity):
Use AT_YYERROR_DEFINE.
2012-06-26 13:55:50 +02:00
Akim Demaille 77519a7d18 tests: use assert instead of plain abort.
* tests/actions.at, tests/calc.at, tests/conflicts.at,
* tests/cxx-type.at, tests/glr-regression.at, tests/input.at,
* tests/named-refs.at, tests/regression.at, tests/torture.at,
* tests/local.at:
Prefer assert to abort.
2012-06-26 13:55:50 +02:00
Akim Demaille 0e16927b48 tests: improve the generic yylex implementation.
* tests/local.at (AT_YYSTYPE, AT_YYLTYPE): New.
(AT_YYLEX_FORMALS): Use them.
(AT_YYLEX_DEFINE): Be independent of the location implementation.
2012-06-26 13:55:49 +02:00
Akim Demaille 91ce0b3a66 tests: generalize the compilation macros.
* tests/local.at (AT_COMPILE, AT_COMPILE_CXX): If OUTPUT ends with ".o",
then append the "natural" extension for the input file (.c or .cc).
If there is no source, pass -c.
* tests/headers.at, tests/input.at, tests/regression.at: Adjust.
2012-06-26 13:55:49 +02:00
Akim Demaille 837b769659 tests: fix confusion between api.prefix and name-prefix.
* tests/local.at (AT_NAME_PREFIX): Take api.prefix into account.
(AT_API_PREFIX): Rename as...
(AT_API_prefix): this.
Do not take %name-prefix into account.
Fix misuses.
2012-06-26 13:55:49 +02:00
Akim Demaille 5e01579ec0 maint: gitignores. 2012-06-26 13:55:49 +02:00
Akim Demaille 55d1006fce yacc: work around the ylwrap limitation.
* data/yacc.c (b4_shared_declarations): Include the header guards.
Do not include the header in the *.c file, duplicate it.
* NEWS (Future Changes): Extend, and announce the forthcoming change
about the use of the parser header.
2012-06-25 10:20:56 +02:00
Akim Demaille 230a3db428 tests: more uniformity.
* tests/local.at (AT_LEX_FORMALS, AT_LEX_ARGS, AT_LEX_PRE_FORMALS)
(AT_LEX_PRE_ARGS): Rename as...
(AT_YYLEX_FORMALS, AT_YYLEX_ARGS, AT_YYLEX_PRE_FORMALS)
(AT_YYLEX_PRE_ARGS): these, for consistency.
(AT_API_PREFIX): Take %name-prefix into account.
(AT_YYLEX_PROTOTYPE): New.
Use it.
* tests/actions.at, tests/calc.at, tests/cxx-type.at: Adjust to
use them.
2012-06-22 12:08:02 +02:00
Akim Demaille 6d55954743 tests: handle locations in a more generic way.
* tests/local.at (AT_YYERROR_PROTOTYPE): New.
Use it.
* tests/cxx-type.at: Extensive revamp to use a more traditional
quotation scheme, and to use the generic yyerror implementation.
Prefer Autotest macros to CPP macros.
* tests/java.at: .
2012-06-22 11:34:37 +02:00
Akim Demaille 7490994123 tests: handle locations in the generic yyerror functions.
* tests/local.at (AT_YYERROR_DECLARE_EXTERN, AT_YYERROR_DECLARE)
(AT_YYERROR_DEFINE): Handle locations for C and C++.
* tests/calc.at: Use it for C++ (as C has extra arguments which
are not yet handled by AT_BISON_OPTION_PUSHDEFS).
* tests/actions.at: Adjust.
2012-06-22 10:20:28 +02:00
Akim Demaille eb46d61f4d tests: fix AT_CHECK_CALC.
* tests/calc.at (AT_CHECK_CALC): Contrary to its documentation,
the test was skipped if given a second argument.
Unused feature, remove it.
2012-06-22 09:41:36 +02:00
Akim Demaille 05a7b6ec80 tests: improve infrastructure
* tests/local.at (AT_LANG): Use c++ instead of cxx for C++.
Adjust dependencies.
(AT_YYERROR_DECLARE_EXTERN, AT_YYERROR_DECLARE): Issue nothing
for C++/Java.
(AT_YYERROR_DEFINE): Use m4_case.
(AT_JAVA_COMPILE): Use AT_SKIP_IF.
2012-06-22 09:30:07 +02:00
Akim Demaille 290a8ff2c0 tests: factor.
* tests/glr-regression.at, tests/output.at, tests/push.at,
* tests/regression.at, tests/torture.at, tests/actions.at:
Use AT_YYLEX_* and AT_YYERROR_*.
2012-06-21 22:54:40 +02:00
Akim Demaille 6e2d7b0974 skeletons: minor style changes
* data/glr.c, data/yacc.c: here.
2012-06-21 17:08:11 +02:00
Akim Demaille 2d40532bf5 tests: AT_LANG.
* tests/local.at (AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS):
Define/undefine AT_LANGE
(AT_LANG_COMPILE): New.
(AT_FULL_COMPILE): Use AT_LANG.
2012-06-21 17:08:11 +02:00
Akim Demaille 756257ee86 c skeletons: factor the declaration of yylloc and yylval.
There is one difference: now, even without --defines, we generate
extern declarations for these variables.  The factoring is worth it.
* data/c.m4 (b4_declare_yylstype): Declare them.
* data/glr.c, data/yacc.c: Adjust.
2012-06-21 15:19:43 +02:00
Akim Demaille 18ad57b384 news: condemn YYPARSE_PARAM and YYLEX_PARAM.
* NEWS: here.
(Bison 1.875): Add %parse-param and %lex-param.
* doc/bison.texinfo: Spello.
2012-06-21 15:19:43 +02:00
Akim Demaille da402d1cae maint: regen.
* Makefile.am (regen): New target.
(cherry picked from commit 71bff31edd)
2012-06-20 10:17:14 +02:00
Akim Demaille e29f0771d7 maint: formatting changes.
* NEWS: Fix indentation of code snippets.
Untabify.
2012-06-19 17:01:35 +02:00
Akim Demaille 71c7e24f2e tests: support api.prefix.
* tests/local.at (AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS):
Define AT_API_PREFIX.
(AT_YYERROR_DEFINE, AT_YYERROR_DECLARE_EXTERN, AT_YYLEX_DECLARE_EXTERN)
(AT_YYLEX_DEFINE): Use it.
* tests/input.at, tests/regression.at, tests/torture.at: Add
AT_BISON_OPTION_PUSHDEFS/POPDEFS.
2012-06-17 19:37:07 +02:00
Akim Demaille 5f7f1e210b tests: pacify font-lock-mode.
* tests/local.at: here.
2012-06-17 19:37:07 +02:00
Akim Demaille eb83259dc1 tests: remove test covered elsewhere.
* tests/headers.at (%union and --defines): Remove, pretty useless and
insignificant.
2012-06-17 19:37:07 +02:00
Akim Demaille 55f48c4831 tests: factor the declaration/definition of yyerror and yylex.
* tests/local.at (AT_YYERROR_DECLARE, AT_YYERROR_DECLARE_EXTERN)
(AT_YYERROR_DEFINE, AT_YYLEX_DECLARE, AT_YYLEX_DECLARE_EXTERN)
(AT_YYLEX_DEFINE): New.
Must be used inside AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
* tests/actions.at, tests/conflicts.at, tests/glr-regression.at,
* tests/headers.at, tests/input.at, tests/named-refs.at,
* tests/regression.at, tests/skeletons.at, tests/synclines.at,
* tests/torture.at: Use them.
2012-06-17 19:37:07 +02:00
Akim Demaille 34d867d7d2 regen. 2012-06-17 12:13:20 +02:00
Akim Demaille 363bf73276 tests: portability issues.
* tests/calc.at (AT_CALC_MAIN): Missing include reported by Hydra.
2012-06-17 11:20:21 +02:00
Akim Demaille c8c220d19a tests: call the parser from another compilation unit.
In order to improve the testing of %defines, which exports the
interface of the generated parser, change the calc.at tests so that
when %defines is passed, main will be in another compilation unit.  It
loads the generated header.

* tests/calc.at (AT_CALC_MAIN): New.
Includes the definition of the global variables.
Therefore, now declare them from the %requires section of the parser.
Adjust to yydebug and yyparse being renamed by %name-prefix.
2012-06-15 15:39:19 +02:00
Akim Demaille 56ca3d8fce glr.c, yacc.c: declare yydebug in the header.
* data/c.m4 (b4_declare_yydebug): New.
* data/glr.c, data/yacc.c (b4_shared_declarations): Use it.
Remove the corresponding code from the parser body.
* NEWS: Doc this.
2012-06-15 15:33:14 +02:00
Akim Demaille c3e9f08f93 skeletons: use header guards.
* data/glr.c, data/glr.cc, data/yacc.c: here.
* NEWS: Document it.
2012-06-15 15:33:14 +02:00
Akim Demaille 6aef2e01a4 tests: improve AT_FULL_COMPILE.
* tests/local.at: Accept a third argument.
Simplify quotation pattern.
Calls for better refactoring, but will suffice for a while.
2012-06-15 15:20:53 +02:00
Akim Demaille 3d8082ad27 tests: reorder.
* tests/calc.at (power): Move its definition, as a preparation for
forthcoming changes.
And space changes.
2012-06-15 13:36:01 +02:00
Akim Demaille 9d67a52ad6 tests: strengthen the test on generated headers inclusion
* tests/headers.at (AT_TEST_CPP_GUARD_H): Accept Bison directives.
(Invalid CPP headers): Check glr.
2012-06-15 13:31:59 +02:00
Akim Demaille 0f11eec272 yacc.c: instead of duplicating y.tab.h inside y.tac.c, include it.
This is already what glr.c and lalr1.cc do.

* data/yacc.c: here.
2012-06-15 13:31:34 +02:00
Akim Demaille ae6bdabbf6 yacc.c: factor.
yacc.c used to include two almost identical sections: one for the *.h
file, and another for the *.c file.  The main difference is that in
the *.c file we used the yy* names (as %name-prefix is handled by
"#define yy* <prefix>*" before), while the *.hh used <prefix>* names.
Keep only the later.  If this is troublesome, b4_shared_declarations
can easily take the desired prefix as argument.

* data/yacc.c (b4_shared_declarations): New.
Use it to factor duplicated declarations.
2012-06-13 21:52:38 +02:00
Akim Demaille c0828abf9d skeletons: factor yacc.c and glr.c.
yacc.c and glr.c share common declarations.  Their YYLTYPE are exactly
equal, and their YYSTYPE are sufficiently alike to be fused (its
declaration was protected by YYSTYPE_IS_DECLARED in yacc.c, but not in
glr.c).  Besides, yacc.c duplicated the definitions of YYLTYPE and
YYSTYPE (*.h/*.c).

* data/c.m4 (b4_declare_yylstype): New.
* data/yacc.c, data/glr.c: Use it.
2012-06-12 14:49:48 +02:00
Akim Demaille e9807a7934 glr.c: minor refactoring.
* data/glr.c (b4_shared_declarations): Move from the generated file
section, to the M4 prologue.
2012-06-12 14:49:48 +02:00
Akim Demaille 02287ec650 tests: remove all the -On flags.
* tests/atlocal.in: Here.
Reported by Gilles Espinasse.
2012-06-12 14:49:48 +02:00
Akim Demaille 6537c71fcc maint: fix spello.
* README-hacking: Here.
* THANKS: Reported by Gilles Espinasse.
2012-06-12 14:49:48 +02:00
Akim Demaille 6733d02476 maint: improve release procedure instructions.
* gnulib: Update, in particular (README-release).
* bootstrap.conf: don't require gendocs, provided by gnu-web-doc-update,
provided by readme-release.
* README-hacking: Update accordingly.
2012-06-12 14:49:15 +02:00
Akim Demaille cc9fb4f6b6 gnulib: update readme-release.
* gnulib (readme-release): Now includes the modules it promotes.
* bootstrap.conf: Simplify accordingly.
2012-06-07 11:15:04 +02:00
Akim Demaille f763e6ef67 maint: cfg.mk: manual title.
* cfg.mk (manuel_title): New.
2012-06-07 11:15:04 +02:00
Akim Demaille c4576b484a maint: cfg.mk: simplify
* cfg.mk: Remove bits provided by maint.mk.
2012-06-07 11:15:04 +02:00
Akim Demaille 91aadcc7a9 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2012-06-07 11:15:04 +02:00
51 changed files with 2452 additions and 2390 deletions
+1 -1
View File
@@ -1 +1 @@
2.5
2.5.91
+11 -9
View File
@@ -66,13 +66,15 @@ update-package-copyright-year:
gen_start_date = 2012-01-16
.PHONY: gen-ChangeLog
gen-ChangeLog:
$(AM_V_GEN)if test -d $(srcdir)/.git; then \
$(top_srcdir)/build-aux/gitlog-to-changelog \
--strip-tab \
--strip-cherry-picked \
--no-cluster \
--amend=$(srcdir)/build-aux/git-log-fix \
--since=$(gen_start_date) > $(distdir)/cl-t; \
rm -f $(distdir)/ChangeLog; \
mv $(distdir)/cl-t $(distdir)/ChangeLog; \
$(AM_V_GEN)if test -d $(srcdir)/.git; then \
cl=$(distdir)/ChangeLog && \
rm -f $$cl.tmp && \
$(top_srcdir)/build-aux/gitlog-to-changelog \
--strip-tab \
--strip-cherry-pick \
--no-cluster \
--amend=$(srcdir)/build-aux/git-log-fix \
--srcdir=$(srcdir) \
--since=$(gen_start_date) > $$cl.tmp && \
mv -f $$cl.tmp $$cl; \
fi
+216 -54
View File
@@ -1,5 +1,138 @@
GNU Bison NEWS
* Noteworthy changes in release 2.6 (2012-07-19) [stable]
** Future Changes
The next major release of Bison will drop support for the following
deprecated features. Please report disagreements to [email protected].
*** K&C parsers
Support for generating parsers in K&R C will be removed. Parsers
generated for C support ISO C90, and are tested with ISO C99 and ISO C11
compilers.
*** Features deprecated since Bison 1.875
The definitions of yystype and yyltype will be removed; use YYSTYPE and
YYLTYPE.
YYPARSE_PARAM and YYLEX_PARAM, deprecated in favor of %parse-param and
%lex-param, will no longer be supported.
Support for the preprocessor symbol YYERROR_VERBOSE will be removed, use
%error-verbose.
*** The generated header will be included (yacc.c)
Instead of duplicating the content of the generated header (definition of
YYSTYPE, yyparse declaration etc.), the generated parser will include it,
as is already the case for GLR or C++ parsers. This change is deferred
because existing versions of ylwrap (e.g., Automake 1.12.1) do not support
it.
** Generated Parser Headers
*** Guards (yacc.c, glr.c, glr.cc)
The generated headers are now guarded, as is already the case for C++
parsers (lalr1.cc). For instance, with --defines=foo.h:
#ifndef YY_FOO_H
# define YY_FOO_H
...
#endif /* !YY_FOO_H */
*** New declarations (yacc.c, glr.c)
The generated header now declares yydebug and yyparse. Both honor
--name-prefix=bar_, and yield
int bar_parse (void);
rather than
#define yyparse bar_parse
int yyparse (void);
in order to facilitate the inclusion of several parser headers inside a
single compilation unit.
*** Exported symbols in C++
The symbols YYTOKEN_TABLE and YYERROR_VERBOSE, which were defined in the
header, are removed, as they prevent the possibility of including several
generated headers from a single compilation unit.
*** YYLSP_NEEDED
For the same reasons, the undocumented and unused macro YYLSP_NEEDED is no
longer defined.
** New %define variable: api.prefix
Now that the generated headers are more complete and properly protected
against multiple inclusions, constant names, such as YYSTYPE are a
problem. While yyparse and others are properly renamed by %name-prefix,
YYSTYPE, YYDEBUG and others have never been affected by it. Because it
would introduce backward compatibility issues in projects not expecting
YYSTYPE to be renamed, instead of changing the behavior of %name-prefix,
it is deprecated in favor of a new %define variable: api.prefix.
The following examples compares both:
%name-prefix "bar_" | %define api.prefix "bar_"
%token <ival> FOO %token <ival> FOO
%union { int ival; } %union { int ival; }
%% %%
exp: 'a'; exp: 'a';
bison generates:
#ifndef BAR_FOO_H #ifndef BAR_FOO_H
# define BAR_FOO_H # define BAR_FOO_H
/* Enabling traces. */ /* Enabling traces. */
# ifndef YYDEBUG | # ifndef BAR_DEBUG
> # if defined YYDEBUG
> # if YYDEBUG
> # define BAR_DEBUG 1
> # else
> # define BAR_DEBUG 0
> # endif
> # else
# define YYDEBUG 0 | # define BAR_DEBUG 0
> # endif
# endif | # endif
# if YYDEBUG | # if BAR_DEBUG
extern int bar_debug; extern int bar_debug;
# endif # endif
/* Tokens. */ /* Tokens. */
# ifndef YYTOKENTYPE | # ifndef BAR_TOKENTYPE
# define YYTOKENTYPE | # define BAR_TOKENTYPE
enum yytokentype { | enum bar_tokentype {
FOO = 258 FOO = 258
}; };
# endif # endif
#if ! defined YYSTYPE \ | #if ! defined BAR_STYPE \
&& ! defined YYSTYPE_IS_DECLARED | && ! defined BAR_STYPE_IS_DECLARED
typedef union YYSTYPE | typedef union BAR_STYPE
{ {
int ival; int ival;
} YYSTYPE; | } BAR_STYPE;
# define YYSTYPE_IS_DECLARED 1 | # define BAR_STYPE_IS_DECLARED 1
#endif #endif
extern YYSTYPE bar_lval; | extern BAR_STYPE bar_lval;
int bar_parse (void); int bar_parse (void);
#endif /* !BAR_FOO_H */ #endif /* !BAR_FOO_H */
* Noteworthy changes in release 2.5.1 (2012-06-05) [stable]
** Future changes:
@@ -37,10 +170,10 @@ GNU Bison NEWS
The header files such as "parser.hh", "location.hh", etc. used a constant
name for preprocessor guards, for instance:
#ifndef BISON_LOCATION_HH
# define BISON_LOCATION_HH
...
#endif // !BISON_LOCATION_HH
#ifndef BISON_LOCATION_HH
# define BISON_LOCATION_HH
...
#endif // !BISON_LOCATION_HH
The inclusion guard is now computed from "PREFIX/FILE-NAME", where lower
case characters are converted to upper case, and series of
@@ -48,10 +181,10 @@ GNU Bison NEWS
With "bison -o lang++/parser.cc", "location.hh" would now include:
#ifndef YY_LANG_LOCATION_HH
# define YY_LANG_LOCATION_HH
...
#endif // !YY_LANG_LOCATION_HH
#ifndef YY_LANG_LOCATION_HH
# define YY_LANG_LOCATION_HH
...
#endif // !YY_LANG_LOCATION_HH
*** C++ locations:
@@ -92,7 +225,7 @@ GNU Bison NEWS
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:
*** The install-pdf target works properly:
Running "make install-pdf" (or -dvi, -html, -info, and -ps) no longer
halts in the middle of its course.
@@ -282,33 +415,33 @@ GNU Bison NEWS
to use it. If, for instance, your location structure has "first"
and "last" members, instead of
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).first = (Rhs)[1].location.first; \
(Current).last = (Rhs)[N].location.last; \
} \
else \
{ \
(Current).first = (Current).last = (Rhs)[0].location.last; \
} \
while (false)
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).first = (Rhs)[1].location.first; \
(Current).last = (Rhs)[N].location.last; \
} \
else \
{ \
(Current).first = (Current).last = (Rhs)[0].location.last; \
} \
while (false)
use:
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).first = YYRHSLOC (Rhs, 1).first; \
(Current).last = YYRHSLOC (Rhs, N).last; \
} \
else \
{ \
(Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
} \
while (false)
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).first = YYRHSLOC (Rhs, 1).first; \
(Current).last = YYRHSLOC (Rhs, N).last; \
} \
else \
{ \
(Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
} \
while (false)
** YYLLOC_DEFAULT in C++:
@@ -927,26 +1060,26 @@ GNU Bison NEWS
if the symbols have destructors. For instance:
exp: exp "?" exp ":" exp { $1 ? $1 : $3; }
| exp "+" exp
;
| exp "+" exp
;
will trigger a warning about $$ and $5 in the first rule, and $3 in
the second ($1 is copied to $$ by the default rule). This example
most likely contains three errors, and could be rewritten as:
exp: exp "?" exp ":" exp
{ $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); }
| exp "+" exp
{ $$ = $1 ? $1 : $3; if ($1) free ($3); }
;
{ $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); }
| exp "+" exp
{ $$ = $1 ? $1 : $3; if ($1) free ($3); }
;
However, if the original actions were really intended, memory leaks
and all, the warnings can be suppressed by letting Bison believe the
values are used, e.g.:
exp: exp "?" exp ":" exp { $1 ? $1 : $3; (void) ($$, $5); }
| exp "+" exp { $$ = $1; (void) $3; }
;
| exp "+" exp { $$ = $1; (void) $3; }
;
If there are mid-rule actions, the warning is issued if no action
uses it. The following triggers no warning: $1 and $3 are used.
@@ -1161,6 +1294,33 @@ GNU Bison NEWS
- "parsing stack overflow..." -> "parser stack overflow"
GLR parsers now report "parser stack overflow" as per the Bison manual.
** %parse-param and %lex-param
The macros YYPARSE_PARAM and YYLEX_PARAM provide a means to pass
additional context to yyparse and yylex. They suffer from several
shortcomings:
- a single argument only can be added,
- their types are weak (void *),
- this context is not passed to ancillary functions such as yyerror,
- only yacc.c parsers support them.
The new %parse-param/%lex-param directives provide a more precise control.
For instance:
%parse-param {int *nastiness}
%lex-param {int *nastiness}
%parse-param {int *randomness}
results in the following signatures:
int yylex (int *nastiness);
int yyparse (int *nastiness, int *randomness);
or, if both %pure-parser and %locations are used:
int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);
int yyparse (int *nastiness, int *randomness);
** Bison now warns if it detects conflicting outputs to the same file,
e.g., it generates a warning for "bison -d -o foo.h foo.y" since
that command outputs both code and header to foo.h.
@@ -1190,16 +1350,16 @@ GNU Bison NEWS
In agreement with POSIX and with other Yaccs, leaving a default
action is valid when $$ is untyped, and $1 typed:
untyped: ... typed;
untyped: ... typed;
but the converse remains an error:
typed: ... untyped;
typed: ... untyped;
** Values of mid-rule actions
The following code:
foo: { ... } { $$ = $1; } ...
foo: { ... } { $$ = $1; } ...
was incorrectly rejected: $1 is defined in the second mid-rule
action, and is equal to the $$ of the first mid-rule action.
@@ -1281,9 +1441,9 @@ GNU Bison NEWS
** Incorrect "Token not used"
On a grammar such as
%token useless useful
%%
exp: '0' %prec useful;
%token useless useful
%%
exp: '0' %prec useful;
where a token was used to set the precedence of the last rule,
bison reported both "useful" and "useless" as useless tokens.
@@ -1302,9 +1462,9 @@ GNU Bison NEWS
the user symbol is used in the reports, the graphs, and the verbose
error messages instead of "$end", which remains being the default.
For instance
%token MYEOF 0
%token MYEOF 0
or
%token MYEOF 0 "end of file"
%token MYEOF 0 "end of file"
** Semantic parser
This old option, which has been broken for ages, is removed.
@@ -1340,9 +1500,9 @@ GNU Bison NEWS
Previous versions don't complain when there is a type clash on
the default action if the rule has a mid-rule action, such as in:
%type <foo> bar
%%
bar: '0' {} '0';
%type <foo> bar
%%
bar: '0' {} '0';
This is fixed.
@@ -1639,9 +1799,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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: Lackovic define's itemset Groff Gettext malloc NEWS'ed YYDEBUG YY
LocalWords: namespaces strerror const autoconfiguration Dconst Autoconf's FDL
LocalWords: Automake TMPDIR LESSEQ
LocalWords: Automake TMPDIR LESSEQ ylwrap endif yydebug YYTOKEN YYLSP ival hh
LocalWords: extern YYTOKENTYPE TOKENTYPE yytokentype tokentype STYPE lval pdf
LocalWords: lang yyoutput dvi html ps POSIX lvalp llocp
Local Variables:
mode: outline
+47 -32
View File
@@ -1,5 +1,3 @@
-*- outline -*-
This file attempts to describe the rules to use when hacking Bison.
Don't put this file into the distribution.
@@ -60,8 +58,8 @@ tools we depend upon, including:
- Rsync <http://samba.anu.edu.au/rsync/>
- Tar <http://www.gnu.org/software/tar/>
Valgrind <http://valgrind.org/> is also highly recommended, if
Valgrind supports your architecture.
Valgrind <http://valgrind.org/> is also highly recommended, if it supports
your architecture.
Bison is written using Bison grammars, so there are bootstrapping
issues. The bootstrap script attempts to discover when the C code
@@ -124,7 +122,7 @@ import requests for updated submodules. A simple "git diff" will
reveal if the current version of the submodule (i.e., the actual
contents of the gnulib directory) and the current request from the
subscriber (i.e., the reference of the version of gnulib that the
Bison reporitory requests) differ. To upgrade the submodules (i.e.,
Bison repository requests) differ. To upgrade the submodules (i.e.,
to check out the version that is actually requested by the subscriber,
run "git submodule update".
@@ -155,7 +153,7 @@ formal release, see the ChangeLog in the latest gnulib snapshot at:
http://erislabs.net/ianb/projects/gnulib/
The autoconf files we use are currently:
The Autoconf files we use are currently:
m4/m4.m4
lib/m4sugar/m4sugar.m4
@@ -170,6 +168,23 @@ decide whether to update.
** make check
Use liberally.
** make maintainer-check-valgrind
This target uses valgrind both to check bison, and the generated parsers.
This is not mature on Mac OS X. First, Valgrind does support the way bison
calls m4, so Valgrind cannot be used to check bison on Mac OS X.
Second, there are many errors that come from the platform itself, not from
bison. build-aux/darwin11.4.0.valgrind addresses some of them.
Third, valgrind issues warnings such as:
--99312:0:syswrap- WARNING: Ignoring sigreturn( ..., UC_RESET_ALT_STACK );
which cause the test to fail uselessly. It is hard to ignore these errors
with a major overhaul of the way instrumentation is performed in the test
suite. So currently, do not try to run valgrind on Mac OS X.
** Release checks
Try to run the test suite with more severe conditions before a
release:
@@ -248,25 +263,13 @@ copyright statement for each Bison file, check the copyright statements
that the skeletons insert into generated parsers, and check all
occurrences of PACKAGE_COPYRIGHT_YEAR in configure.ac.
** Update NEWS
The version number, *and* the date of the release (including for
betas).
** Update NEWS, commit and tag.
See do-release-commit-and-tag in README-release. For a while, we used
beta names such as "2.6_rc1". Now that we use gnulib in the release
procedure, we must use "2.5.90", which has the additional benefit of
being properly sorted in "git tag -l".
** Mention the release name in a commit message
Should have an entry similar to "Version 2.3b.".
** Tag the release
Before Bison will build with the right version number, you must tag
the release in git. Do this after all other changes. The command is
similar to:
git tag -a v2.3b -m "Bison 2.3b."
** Push
Once "make distcheck" passes, push your changes and the tag.
"git push" without arguments will not push the tag.
** make alpha, beta, or release
** make alpha, beta, or stable
See README-release.
** Upload
@@ -287,8 +290,8 @@ where F125BDF3 should be replaced with your key ID.
*** Using gnupload
You need "ncftp".
At the end "make release" (or alpha/beta) will display the prodecure
to run. Just copy and paste it in your shell.
At the end "make stable" (or alpha/beta) will display the procedure to
run. Just copy and paste it in your shell.
*** By hand
@@ -359,7 +362,8 @@ function 'index', once for the table of contents); you can ignore this
issue.
** Announce
To generate a template announcement file:
The "make stable" (or alpha/beta) command just created a template,
$HOME/announce-bison-X.Y. Otherwise, to generate it, run:
make RELEASE_TYPE=alpha gpg_key_ID=F125BDF3 announcement
@@ -379,15 +383,15 @@ newsgroup by sending email to [email protected]. Do not make any Cc as
the moderator will throw away anything cross-posted or Cc'ed. It really
needs to be a separate message.
** Bump the version number
In configure.ac. Run "make". So that developers don't accidentally add new
items to the old NEWS entry, create a new empty NEWS entry something like:
** Prepare NEWS
So that developers don't accidentally add new items to the old NEWS
entry, create a new empty entry in line 3 (without the two leading
spaces):
Changes in version ?.? (????-??-??):
* Noteworthy changes in release ?.? (????-??-??) [?]
Push these changes.
-----
Copyright (C) 2002-2005, 2007-2012 Free Software Foundation, Inc.
@@ -406,3 +410,14 @@ 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 <http://www.gnu.org/licenses/>.
LocalWords: Automake Autoconf Gettext Gzip Rsync Valgrind gnulib submodules
LocalWords: submodule init cd distcheck checkin ChangeLog valgrind sigreturn
LocalWords: UC gcc DGNULIB POSIXCHECK xml XSLT glr lalr README po runtime rc
LocalWords: gnupload gnupg gpg keyserver BDF ncftp filename clearsign cvs dir
LocalWords: symlinks vti html lt POSIX Cc'ed
Local Variables:
mode: outline
fill-column: 76
End:
+1
View File
@@ -43,6 +43,7 @@ Frank Heckenbach [email protected]
Frans Englich [email protected]
Georg Sauthoff [email protected]
George Neuner [email protected]
Gilles Espinasse [email protected]
Goran Uddeborg [email protected]
Guido Trentalancia [email protected]
H. Merijn Brand [email protected]
-6
View File
@@ -126,12 +126,6 @@ The code bw glr.c and yacc.c is really alike, we can certainly factor
some parts.
* Yacc.c: CPP Macros
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...).
* Report
** Figures
+67 -49
View File
@@ -1,6 +1,6 @@
#! /bin/sh
# Print a version string.
scriptversion=2012-05-15.06; # UTC
scriptversion=2012-07-10.09; # UTC
# Bootstrap this package from checked-out sources.
@@ -77,6 +77,33 @@ Running without arguments will suffice in most cases.
EOF
}
# warnf_ FORMAT-STRING ARG1...
warnf_ ()
{
warnf_format_=$1
shift
nl='
'
case $* in
*$nl*) me_=$(printf "$me"|tr "$nl|" '??')
printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;;
*) printf "$me: $warnf_format_" "$@" ;;
esac >&2
}
# warn_ WORD1...
warn_ ()
{
# If IFS does not start with ' ', set it and emit the warning in a subshell.
case $IFS in
' '*) warnf_ '%s\n' "$*";;
*) (IFS=' '; warn_ "$@");;
esac
}
# die WORD1...
die() { warn_ "$@"; exit 1; }
# Configuration.
# Name of the Makefile.am
@@ -130,7 +157,8 @@ extract_package_name='
p
}
'
package=$(sed -n "$extract_package_name" configure.ac) || exit
package=$(sed -n "$extract_package_name" configure.ac) \
|| die 'cannot find package name in configure.ac'
gnulib_name=lib$package
build_aux=build-aux
@@ -203,19 +231,15 @@ find_tool ()
else
find_tool_error_prefix="\$$find_tool_envvar: "
fi
if test x"$find_tool_res" = x; then
echo >&2 "$me: one of these is required: $find_tool_names"
exit 1
fi
($find_tool_res --version </dev/null) >/dev/null 2>&1 || {
echo >&2 "$me: ${find_tool_error_prefix}cannot run $find_tool_res --version"
exit 1
}
test x"$find_tool_res" != x \
|| die "one of these is required: $find_tool_names"
($find_tool_res --version </dev/null) >/dev/null 2>&1 \
|| die "${find_tool_error_prefix}cannot run $find_tool_res --version"
eval "$find_tool_envvar=\$find_tool_res"
eval "export $find_tool_envvar"
}
# Find sha1sum, named gsha1sum on MacPorts, and shasum on MacOS 10.6.
# Find sha1sum, named gsha1sum on MacPorts, and shasum on Mac OS X 10.6.
find_tool SHA1SUM sha1sum gsha1sum shasum
# Override the default configuration, if necessary.
@@ -230,7 +254,6 @@ esac
test -z "${gnulib_extra_files}" && \
gnulib_extra_files="
$build_aux/install-sh
$build_aux/missing
$build_aux/mdate-sh
$build_aux/texinfo.tex
$build_aux/depcomp
@@ -270,21 +293,15 @@ do
--no-git)
use_git=false;;
*)
echo >&2 "$0: $option: unknown option"
exit 1;;
die "$option: unknown option";;
esac
done
if $use_git || test -d "$GNULIB_SRCDIR"; then
:
else
echo "$0: Error: --no-git requires --gnulib-srcdir" >&2
exit 1
fi
$use_git || test -d "$GNULIB_SRCDIR" \
|| die "Error: --no-git requires --gnulib-srcdir"
if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
echo "$0: Bootstrapping from a non-checked-out distribution is risky." >&2
exit 1
die "Bootstrapping from a non-checked-out distribution is risky."
fi
# Ensure that lines starting with ! sort last, per gitignore conventions
@@ -310,7 +327,7 @@ insert_sorted_if_absent() {
echo "$str" | sort_patterns - $file | cmp -s - $file > /dev/null \
|| { echo "$str" | sort_patterns - $file > $file.bak \
&& mv $file.bak $file; } \
|| exit 1
|| die "insert_sorted_if_absent $file $str: failed"
}
# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
@@ -334,11 +351,8 @@ grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
>/dev/null && found_aux_dir=yes
grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
>/dev/null && found_aux_dir=yes
if test $found_aux_dir = no; then
echo "$0: expected line not found in configure.ac. Add the following:" >&2
echo " AC_CONFIG_AUX_DIR([$build_aux])" >&2
exit 1
fi
test $found_aux_dir = yes \
|| die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
# If $build_aux doesn't exist, create it now, otherwise some bits
# below will malfunction. If creating it, also mark it as ignored.
@@ -444,7 +458,7 @@ check_versions() {
automake-ng|aclocal-ng)
app=${app%-ng}
($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
echo "$me: Error: '$app' not found or not from Automake-NG" >&2
warn_ "Error: '$app' not found or not from Automake-NG"
ret=1
continue
} ;;
@@ -454,20 +468,21 @@ check_versions() {
# so we have to rely on $? rather than get_version.
$app --version >/dev/null 2>&1
if [ 126 -le $? ]; then
echo "$me: Error: '$app' not found" >&2
warn_ "Error: '$app' not found"
ret=1
fi
else
# Require app to produce a new enough version string.
inst_ver=$(get_version $app)
if [ ! "$inst_ver" ]; then
echo "$me: Error: '$app' not found" >&2
warn_ "Error: '$app' not found"
ret=1
else
latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
if [ ! "$latest_ver" = "$inst_ver" ]; then
echo "$me: Error: '$app' version == $inst_ver is too old" >&2
echo " '$app' version >= $req_ver is required" >&2
warnf_ '%s\n' \
"Error: '$app' version == $inst_ver is too old" \
" '$app' version >= $req_ver is required"
ret=1
fi
fi
@@ -524,11 +539,10 @@ fi
if ! printf "$buildreq" | check_versions; then
echo >&2
if test -f README-prereq; then
echo "$0: See README-prereq for how to get the prerequisite programs" >&2
die "See README-prereq for how to get the prerequisite programs"
else
echo "$0: Please install the prerequisite programs" >&2
die "Please install the prerequisite programs"
fi
exit 1
fi
echo "$0: Bootstrapping from checked-out $package sources..."
@@ -739,11 +753,10 @@ symlink_to_dir()
*)
case /$dst/ in
*//* | */../* | */./* | /*/*/*/*/*/)
echo >&2 "$me: invalid symlink calculation: $src -> $dst"
exit 1;;
/*/*/*/*/) dot_dots=../../../;;
/*/*/*/) dot_dots=../../;;
/*/*/) dot_dots=../;;
die "invalid symlink calculation: $src -> $dst";;
/*/*/*/*/) dot_dots=../../../;;
/*/*/*/) dot_dots=../../;;
/*/*/) dot_dots=../;;
esac;;
esac
@@ -765,7 +778,7 @@ version_controlled_file() {
grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
grep '^/[^/]*/[0-9]' > /dev/null
else
echo "$me: no version control for $file?" >&2
warn_ "no version control for $file?"
false
fi
}
@@ -855,11 +868,12 @@ echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
$gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
for file in $gnulib_files; do
symlink_to_dir "$GNULIB_SRCDIR" $file || exit
symlink_to_dir "$GNULIB_SRCDIR" $file \
|| die "failed to symlink $file"
done
bootstrap_post_import_hook \
|| { echo >&2 "$me: bootstrap_post_import_hook failed"; exit 1; }
|| die "bootstrap_post_import_hook failed"
# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
# gnulib-populated directories. Such .m4 files would cause aclocal to fail.
@@ -887,7 +901,7 @@ echo "running: AUTOPOINT=true LIBTOOLIZE=true " \
"$AUTORECONF --verbose --install $no_recursive -I $m4_base $ACLOCAL_FLAGS"
AUTOPOINT=true LIBTOOLIZE=true \
$AUTORECONF --verbose --install $no_recursive -I $m4_base $ACLOCAL_FLAGS \
|| exit 1
|| die "autoreconf failed"
# Get some extra files from gnulib, overriding existing files.
for file in $gnulib_extra_files; do
@@ -896,7 +910,8 @@ for file in $gnulib_extra_files; do
build-aux/*) dst=$build_aux/${file#build-aux/};;
*) dst=$file;;
esac
symlink_to_dir "$GNULIB_SRCDIR" $file $dst || exit
symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
|| die "failed to symlink $file"
done
if test $with_gettext = yes; then
@@ -912,7 +927,8 @@ if test $with_gettext = yes; then
a\
'"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
}
' po/Makevars.template >po/Makevars || exit 1
' po/Makevars.template >po/Makevars \
|| die 'cannot generate po/Makevars'
# If the 'gettext' module is in use, grab the latest Makefile.in.in.
# If only the 'gettext-h' module is in use, assume autopoint already
@@ -920,7 +936,8 @@ if test $with_gettext = yes; then
case $gnulib_modules in
*gettext-h*) ;;
*gettext*)
cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in || exit 1
cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
|| die "cannot create po/Makefile.in.in"
;;
esac
@@ -936,7 +953,8 @@ if test $with_gettext = yes; then
a\
'"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
}
' po/Makevars.template >runtime-po/Makevars || exit 1
' po/Makevars.template >runtime-po/Makevars \
|| die 'cannot generate runtime-po/Makevars'
# Copy identical files from po to runtime-po.
(cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
+3 -4
View File
@@ -17,14 +17,13 @@
# gnulib modules used by this package.
gnulib_modules='
announce-gen argmatch assert calloc-posix close closeout config-h c-strcase
argmatch assert calloc-posix close closeout config-h c-strcase
configmake
dirname
do-release-commit-and-tag
error extensions fdl fopen-safer gendocs getopt-gnu
error extensions fdl fopen-safer getopt-gnu
gettext git-version-gen gitlog-to-changelog
gpl-3.0 hash inttypes isnan javacomp-script
javaexec-script ldexpl maintainer-makefile malloc-gnu mbschr mbsrchr
javaexec-script ldexpl malloc-gnu mbschr mbsrchr
mbswidth obstack perror progname
quote quotearg
readme-release
+3 -1
View File
@@ -8,9 +8,12 @@
/config.rpath
/config.sub
/depcomp
/do-release-commit-and-tag
/gendocs.sh
/git-version-gen
/gitlog-to-changelog
/gnu-web-doc-update
/gnupload
/install-sh
/javacomp.sh.in
/javaexec.sh.in
@@ -23,4 +26,3 @@
/vc-list-files
/warn-on-use.h
/ylwrap
/do-release-commit-and-tag
+20 -2
View File
@@ -1,2 +1,20 @@
## Process this file with automake to produce Makefile.in -*-Makefile-*-
EXTRA_DIST = prev-version.txt cross-options.pl update-b4-copyright
## Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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 <http://www.gnu.org/licenses/>.
EXTRA_DIST = \
cross-options.pl \
darwin11.4.0.valgrind \
prev-version.txt \
update-b4-copyright
+64
View File
@@ -0,0 +1,64 @@
# Copyright (C) 2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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 <http://www.gnu.org/licenses/>.
# Valgrind suppression file for Bison.
{
Mac OS X initialization
Memcheck:Leak
fun:?alloc*
...
fun:*ImageLoader*
}
{
Mac OS X initialization
Memcheck:Leak
fun:?alloc*
...
fun:*dyld*
}
{
Mac OS X initialization
Memcheck:Leak
fun:?alloc*
...
fun:__CFInitialize
}
{
Mac OS X I/O buffer
Memcheck:Leak
fun:malloc
fun:__smakebuf
fun:__swsetup
fun:__sfvwrite
fun:fwrite
}
{
Mac OS X I/O buffer
Memcheck:Leak
fun:malloc
fun:__smakebuf
fun:__swsetup
fun:__swbuf
fun:putchar
}
# Local Variables:
# mode: shell-script
# End:
+4
View File
@@ -0,0 +1,4 @@
/_Noreturn.h
/arg-nonnull.h
/c++defs.h
/warn-on-use.h
+15 -10
View File
@@ -1,5 +1,4 @@
# Customize maint.mk -*- makefile -*-
# Copyright (C) 2008-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
@@ -15,6 +14,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Update version, then recompile so that tests/bison --version be
# up-to-date, then compile our parser again with our up-to-date bison.
.PHONY: regen
regen: _version
$(MAKE) $(AM_MAKEFLAGS)
touch $(srcdir)/src/parse-gram.y
$(MAKE) $(AM_MAKEFLAGS)
# Used in maint.mk's web-manual rule
manual_title = The Yacc-compatible Parser Generator
# It's useful to run maintainer-*check* targets during development, but we
# don't want to wait on a recompile because of an update to $(VERSION). Thus,
# override the _is-dist-target from GNUmakefile so that maintainer-*check*
@@ -22,13 +32,6 @@
_is-dist-target = $(filter-out %clean maintainer-check% maintainer-%-check, \
$(filter maintainer-% dist% alpha beta major,$(MAKECMDGOALS)))
# Use alpha.gnu.org for alpha and beta releases.
# Use ftp.gnu.org for major releases.
gnu_ftp_host-alpha = alpha.gnu.org
gnu_ftp_host-beta = alpha.gnu.org
gnu_ftp_host-major = ftp.gnu.org
gnu_rel_host = $(gnu_ftp_host-$(RELEASE_TYPE))
url_dir_list = \
ftp://$(gnu_rel_host)/gnu/bison
@@ -57,7 +60,8 @@ update-copyright: update-b4-copyright update-package-copyright-year
update-copyright-env = \
UPDATE_COPYRIGHT_FORCE=1 UPDATE_COPYRIGHT_USE_INTERVALS=1
exclude = $(foreach a,$(1),$(eval exclude_file_name_regexp--sc_$(a)))
exclude = \
$(foreach a,$(1),$(eval $(subst $$,$$$$,exclude_file_name_regexp--sc_$(a))))
$(call exclude, \
bindtextdomain=^lib/main.c$$ \
program_name=^lib/main.c$$ \
@@ -65,9 +69,10 @@ $(call exclude, \
prohibit_always-defined_macros+=?|^lib/timevar.c$$ \
prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \
prohibit_always-defined_macros+=?|^tests/regression.at$$ \
prohibit_defined_have_decl_tests=?|^lib/timevar.c$$ \
prohibit_empty_lines_at_EOF=^src/parse-gram.[ch]$$ \
require_config_h_first=^(lib/yyerror|data/(glr|yacc))\.c$$ \
space_tab=^tests/(input|c\+\+)\.at$$ \
trailing_blank=^src/parse-gram.[ch]$$ \
unmarked_diagnostics=^djgpp/ \
unmarked_diagnostics=^(djgpp/|doc/bison.texi$$) \
)
+10
View File
@@ -163,6 +163,16 @@ AC_CONFIG_TESTDIR(tests)
AC_CONFIG_FILES([tests/Makefile tests/atlocal])
AC_CONFIG_FILES([tests/bison], [chmod +x tests/bison])
AC_CHECK_PROGS([VALGRIND], [valgrind])
case $VALGRIND:$host_os in
'':*) ;;
*:darwin*)
# See README-hacking.
# VALGRIND+=' --suppressions=$(abs_top_srcdir)/build-aux/darwin11.4.0.valgrind'
VALGRIND=;;
*:*)
AC_SUBST([VALGRIND_PREBISON], [$VALGRIND -q]);;
esac
AM_MISSING_PROG([AUTOM4TE], [autom4te])
# Needed by tests/atlocal.in.
AC_SUBST([GCC])
+35 -27
View File
@@ -183,21 +183,6 @@ m4_define([b4_fatal_at],
m4_exit(1)])
## ---------------- ##
## Default values. ##
## ---------------- ##
# m4_define_default([b4_lex_param], []) dnl breaks other skeletons
m4_define_default([b4_pre_prologue], [])
m4_define_default([b4_post_prologue], [])
m4_define_default([b4_epilogue], [])
m4_define_default([b4_parse_param], [])
# The initial column and line.
m4_define_default([b4_location_initial_column], [1])
m4_define_default([b4_location_initial_line], [1])
## ------------ ##
## Data Types. ##
## ------------ ##
@@ -233,9 +218,9 @@ m4_define([b4_define_flag_if],
# _b4_define_flag_if($1, $2, FLAG)
# --------------------------------
# This macro works around the impossibility to define macros
# inside macros, because issuing `[$1]' is not possible in M4 :(.
# This sucks hard, GNU M4 should really provide M5 like $$1.
# Work around the impossibility to define macros inside macros,
# because issuing `[$1]' is not possible in M4. GNU M4 should provide
# $$1 a la M5/TeX.
m4_define([_b4_define_flag_if],
[m4_if([$1$2], $[1]$[2], [],
[m4_fatal([$0: Invalid arguments: $@])])dnl
@@ -246,17 +231,17 @@ m4_define([b4_$3_if],
# b4_FLAG_if(IF-TRUE, IF-FALSE)
# -----------------------------
# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
b4_define_flag_if([defines]) # Whether headers are requested.
b4_define_flag_if([error_verbose]) # Whether error are verbose.
b4_define_flag_if([glr]) # Whether a GLR parser is requested.
b4_define_flag_if([locations]) # Whether locations are tracked.
b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
b4_define_flag_if([defines]) # Whether headers are requested.
b4_define_flag_if([error_verbose]) # Whether error are verbose.
b4_define_flag_if([glr]) # Whether a GLR parser is requested.
b4_define_flag_if([locations]) # Whether locations are tracked.
b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
b4_define_flag_if([token_table]) # Whether yytoken_table is demanded.
b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
# yytoken_table is needed to support verbose errors.
b4_error_verbose_if([m4_define([b4_token_table_flag], [1])])
## ------------------------- ##
## Assigning token numbers. ##
## ------------------------- ##
## ----------- ##
@@ -576,3 +561,26 @@ m4_wrap_lifo([
b4_check_user_names_wrap([[define]], [[variable]])
b4_check_user_names_wrap([[code]], [[qualifier]])
])
## ---------------- ##
## Default values. ##
## ---------------- ##
# m4_define_default([b4_lex_param], []) dnl breaks other skeletons
m4_define_default([b4_pre_prologue], [])
m4_define_default([b4_post_prologue], [])
m4_define_default([b4_epilogue], [])
m4_define_default([b4_parse_param], [])
# The initial column and line.
m4_define_default([b4_location_initial_column], [1])
m4_define_default([b4_location_initial_line], [1])
# Sanity checks.
b4_percent_define_ifdef([api.prefix],
[m4_ifdef([b4_prefix],
[b4_complain_at(b4_percent_define_get_loc([api.prefix]),
[['%s' and '%s' cannot be used together]],
[%name-prefix],
[%define api.prefix])])])
+29
View File
@@ -174,3 +174,32 @@ m4_define([b4_cc_var_decls],
], [$@])])
m4_define([b4_cc_var_decl],
[ $1;])
## ---------##
## Values. ##
## ---------##
# b4_yylloc_default_define
# ------------------------
# Define YYLLOC_DEFAULT.
m4_define([b4_yylloc_default_define],
[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
# ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).begin = YYRHSLOC (Rhs, 1).begin; \
(Current).end = YYRHSLOC (Rhs, N).end; \
} \
else \
{ \
(Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
} \
while (/*CONSTCOND*/ false)
# endif
]])
+123 -14
View File
@@ -77,9 +77,6 @@ m4_define([b4_identification],
/* Pull parsers. */
#define YYPULL ]b4_pull_flag])[
/* Using locations. */
#define YYLSP_NEEDED ]b4_locations_flag[
]])
@@ -87,11 +84,24 @@ m4_define([b4_identification],
## Default values. ##
## ---------------- ##
# If the %union is not named, its name is YYSTYPE.
m4_define_default([b4_union_name], [YYSTYPE])
# b4_api_prefix, b4_api_PREFIX
# ----------------------------
# Corresponds to %define api.prefix
b4_percent_define_default([[api.prefix]], [[yy]])
m4_define([b4_api_prefix],
[b4_percent_define_get([[api.prefix]])])
m4_define([b4_api_PREFIX],
[m4_toupper(b4_api_prefix)])
# b4_prefix
# ---------
# If the %name-prefix is not given, it is api.prefix.
m4_define_default([b4_prefix], [b4_api_prefix])
# If the %union is not named, its name is YYSTYPE.
m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE])
# If the %name-prefix is not given, it is yy.
m4_define_default([b4_prefix], [yy])
## ------------------------ ##
## Pure/impure interfaces. ##
@@ -235,18 +245,18 @@ m4_define([b4_token_enum],
# Output the definition of the tokens (if there are) as enums.
m4_define([b4_token_enums],
[m4_if([$#$1], [1], [],
[/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
[[/* Tokens. */
#ifndef ]b4_api_PREFIX[TOKENTYPE
# define ]b4_api_PREFIX[TOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
m4_map_sep([ b4_token_enum], [,
enum ]b4_api_prefix[tokentype {
]m4_map_sep([ b4_token_enum], [,
],
[$@])
[$@])[
};
#endif
])])
]])])
# b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
@@ -530,3 +540,102 @@ b4_locations_if([, yylocationp])[]b4_user_args[);
YYFPRINTF (yyoutput, ")");
}]dnl
])
## -------------- ##
## Declarations. ##
## -------------- ##
# b4_declare_yylstype
# -------------------
# Declarations that might either go into the header (if --defines) or
# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc.
m4_define([b4_declare_yylstype],
[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
]m4_ifdef([b4_stype],
[[typedef union ]b4_union_name[
{
]b4_user_stype[
} ]b4_api_PREFIX[STYPE;
# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]],
[m4_if(b4_tag_seen_flag, 0,
[[typedef int ]b4_api_PREFIX[STYPE;
# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]])])[
# define ]b4_api_prefix[stype ]b4_api_PREFIX[STYPE /* obsolescent; will be withdrawn */
# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
#endif]b4_locations_if([[
#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED
typedef struct ]b4_api_PREFIX[LTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} ]b4_api_PREFIX[LTYPE;
# define ]b4_api_prefix[ltype ]b4_api_PREFIX[LTYPE /* obsolescent; will be withdrawn */
# define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1
# define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1
#endif]])
b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval;
]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl
])
# b4_YYDEBUG_define
# ------------------
m4_define([b4_YYDEBUG_define],
[[/* Enabling traces. */
]m4_if(b4_api_prefix, [yy],
[[#ifndef YYDEBUG
# define YYDEBUG ]b4_debug_flag[
#endif]],
[[#ifndef ]b4_api_PREFIX[DEBUG
# if defined YYDEBUG
# if YYDEBUG
# define ]b4_api_PREFIX[DEBUG 1
# else
# define ]b4_api_PREFIX[DEBUG 0
# endif
# else /* ! defined YYDEBUG */
# define ]b4_api_PREFIX[DEBUG ]b4_debug_flag[
# endif /* ! defined ]b4_api_PREFIX[DEBUG */
#endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl
])
# b4_declare_yydebug
# ------------------
m4_define([b4_declare_yydebug],
[b4_YYDEBUG_define[
#if ]b4_api_PREFIX[DEBUG
extern int ]b4_prefix[debug;
#endif][]dnl
])
# b4_yylloc_default_define
# ------------------------
# Define YYLLOC_DEFAULT.
m4_define([b4_yylloc_default_define],
[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (YYID (N)) \
{ \
(Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
(Current).last_line = YYRHSLOC (Rhs, N).last_line; \
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
} \
else \
{ \
(Current).first_line = (Current).last_line = \
YYRHSLOC (Rhs, 0).last_line; \
(Current).first_column = (Current).last_column = \
YYRHSLOC (Rhs, 0).last_column; \
} \
while (YYID (0))
#endif
]])
+61 -113
View File
@@ -18,7 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
m4_include(b4_pkgdatadir/[c.m4])
# If we are loaded by glr.cc, do not override c++.m4 definitions by
# those of c.m4.
m4_if(b4_skeleton, ["glr.c"],
[m4_include(b4_pkgdatadir/[c.m4])])
## ---------------- ##
## Default values. ##
@@ -154,6 +157,23 @@ m4_define([b4_rhs_location],
[(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yyloc)])
## -------------- ##
## Declarations. ##
## -------------- ##
# b4_shared_declarations
# ----------------------
# Declaration that might either go into the header (if --defines)
# or open coded in the parser body.
m4_define([b4_shared_declarations],
[b4_declare_yydebug[
]b4_percent_code_get([[requires]])[
]b4_token_enums(b4_tokens)[
]b4_declare_yylstype[
]b4_c_ansi_function_decl(b4_prefix[parse], [int], b4_parse_param)[
]b4_percent_code_get([[provides]])[]dnl
])
## -------------- ##
## Output files. ##
@@ -170,66 +190,29 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
]b4_identification
b4_percent_code_get([[top]])[]dnl
m4_if(b4_prefix, [yy], [],
[/* Substitute the variable and function names. */
#define yyparse b4_prefix[]parse
#define yylex b4_prefix[]lex
#define yyerror b4_prefix[]error
#define yylval b4_prefix[]lval
#define yychar b4_prefix[]char
#define yydebug b4_prefix[]debug
#define yynerrs b4_prefix[]nerrs
#define yylloc b4_prefix[]lloc])[
b4_percent_code_get([[top]])[
]m4_if(b4_api_prefix, [yy], [],
[[/* Substitute the type names. */
#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
]m4_if(b4_prefix, [yy], [],
[[/* Substitute the variable and function names. */
#define yyparse ]b4_prefix[parse
#define yylex ]b4_prefix[lex
#define yyerror ]b4_prefix[error
#define yylval ]b4_prefix[lval
#define yychar ]b4_prefix[char
#define yydebug ]b4_prefix[debug
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
#define yylloc ]b4_prefix[lloc]])])[
/* Copy the first part of user declarations. */
]b4_user_pre_prologue
]b4_user_pre_prologue[
b4_null_define
]b4_null_define[
dnl # b4_shared_declarations
dnl # ----------------------
dnl # Declaration that might either go into the header (if --defines)
dnl # or open coded in the parser body.
m4_define([b4_shared_declarations],
[b4_percent_code_get([[requires]])[]dnl
b4_token_enums(b4_tokens)
[#ifndef YYSTYPE
]m4_ifdef([b4_stype],
[[typedef union ]b4_union_name[
{
]b4_user_stype[
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1]],
[m4_if(b4_tag_seen_flag, 0,
[[typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1]])])[
#endif
]b4_locations_if([[
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
]])[
]b4_percent_code_get([[provides]])[]dnl
])
b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
[b4_shared_declarations])[
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG ]b4_debug_flag[
#endif
]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
[b4_shared_declarations])[
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
@@ -239,11 +222,6 @@ b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
# define YYERROR_VERBOSE ]b4_error_verbose_flag[
#endif
/* Enabling the token table. */
#ifndef YYTOKEN_TABLE
# define YYTOKEN_TABLE ]b4_token_table[
#endif
/* Default (constant) value used for initialization for null
right-hand sides. Unlike the standard yacc.c template,
here we set the default value of $$ to a zeroed-out value.
@@ -370,7 +348,7 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
]b4_translate[
};
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
@@ -391,7 +369,7 @@ static const ]b4_int_type_for([b4_rline])[ yyrline[] =
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
@@ -492,37 +470,13 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
]b4_stos[
};
/* Prevent warning if -Wmissing-prototypes. */
]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
/* Error token number */
#define YYTERROR 1
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
]b4_locations_if([[
#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (YYID (N)) \
{ \
(Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
(Current).last_line = YYRHSLOC (Rhs, N).last_line; \
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
} \
else \
{ \
(Current).first_line = (Current).last_line = \
YYRHSLOC (Rhs, 0).last_line; \
(Current).first_column = (Current).last_column = \
YYRHSLOC (Rhs, 0).last_column; \
} \
while (YYID (0))
]b4_yylloc_default_define[
# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
/* YY_LOCATION_PRINT -- Print the location on the stream.
This macro was not mandated originally: define only if we know
@@ -543,7 +497,6 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
#endif
/* YYLEX -- calling `yylex' with the right arguments. */
#define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
@@ -577,7 +530,7 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
while (YYID (0))
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
# ifndef YYFPRINTF
# define YYFPRINTF fprintf
@@ -605,12 +558,12 @@ do { \
multiple parsers can coexist. */
int yydebug;
#else /* !YYDEBUG */
#else /* !]b4_api_PREFIX[DEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
#endif /* !YYDEBUG */
#endif /* !]b4_api_PREFIX[DEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
@@ -637,8 +590,8 @@ int yydebug;
#ifndef YYSTACKEXPANDABLE
# if (! defined __cplusplus \
|| (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
&& ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
|| (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
&& ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))
# define YYSTACKEXPANDABLE 1
# else
# define YYSTACKEXPANDABLE 0
@@ -849,7 +802,7 @@ yyMemoryExhausted (yyGLRStack* yystackp)
YYLONGJMP (yystackp->yyexception_buffer, 2);
}
#if YYDEBUG || YYERROR_VERBOSE
#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
/** A printable representation of TOKEN. */
static inline const char*
yytokenName (yySymbol yytoken)
@@ -986,7 +939,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
&yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
else
{
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
if (yydebug)
{
if (yys->yysemantics.yyfirstVal)
@@ -1415,7 +1368,7 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
}
}
#if !YYDEBUG
#if !]b4_api_PREFIX[DEBUG
# define YY_REDUCE_PRINT(Args)
#else
# define YY_REDUCE_PRINT(Args) \
@@ -1736,7 +1689,7 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
return yyflag;
}
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
static void
yyreportTree (yySemanticOption* yyx, int yyindent)
{
@@ -1791,7 +1744,7 @@ yyreportAmbiguity (yySemanticOption* yyx0,
YYUSE (yyx0);
YYUSE (yyx1);
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
YYFPRINTF (stderr, "Ambiguity detected.\n");
YYFPRINTF (stderr, "Option 1,\n");
yyreportTree (yyx0, 2);
@@ -2343,7 +2296,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
yychar = YYEMPTY;
yylval = yyval_default;
]b4_locations_if([
#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
#if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
#endif
@@ -2575,7 +2528,7 @@ m4_popdef([b4_at_dollar])])dnl
}
/* DEBUGGING ONLY */
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
static void yypstack (yyGLRStack* yystackp, size_t yyk)
__attribute__ ((__unused__));
static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
@@ -2658,15 +2611,10 @@ m4_if(b4_skeleton, ["glr.c"],
[b4_defines_if(
[@output(b4_spec_defines_file@)@
b4_copyright([Skeleton interface for Bison GLR parsers in C],
[2002-2012])
[2002-2012])[
b4_shared_declarations
b4_pure_if([],
[[extern YYSTYPE ]b4_prefix[lval;]])
b4_locations_if([b4_pure_if([],
[extern YYLTYPE ]b4_prefix[lloc;])
])
])])
]b4_cpp_guard_open([b4_spec_defines_file])[
]b4_shared_declarations[
]b4_cpp_guard_close([b4_spec_defines_file])[
]])])
m4_divert_pop(0)
+36 -61
View File
@@ -78,9 +78,9 @@ m4_define([b4_yy_symbol_print_generate],
[static void],
[[FILE *], []],
[[int yytype], [yytype]],
[[const b4_namespace_ref::b4_parser_class_name::semantic_type *yyvaluep],
[[const ]b4_namespace_ref::b4_parser_class_name[::semantic_type *yyvaluep],
[yyvaluep]],
[[const b4_namespace_ref::b4_parser_class_name::location_type *yylocationp],
[[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
[yylocationp]],
b4_parse_param)[
{
@@ -90,19 +90,22 @@ m4_define([b4_yy_symbol_print_generate],
]])
# Declare yyerror.
# Hijack the post prologue to insert early definition of YYLLOC_DEFAULT
# and declaration of yyerror.
m4_append([b4_post_prologue],
[b4_syncline([@oline@], [@ofile@])
b4_c_ansi_function_decl([yyerror],
[b4_syncline([@oline@], [@ofile@])[
]b4_yylloc_default_define[
#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
]b4_c_ansi_function_decl([yyerror],
[static void],
[[const b4_namespace_ref::b4_parser_class_name::location_type *yylocationp],
[[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
[yylocationp]],
b4_parse_param,
[[const char* msg], [msg]])])
# Define yyerror.
# Hijack the epilogue to define implementations (yyerror, parser member
# functions etc.).
m4_append([b4_epilogue],
[b4_syncline([@oline@], [@ofile@])[
/*------------------.
@@ -111,7 +114,7 @@ m4_append([b4_epilogue],
]b4_c_ansi_function_def([yyerror],
[static void],
[[const b4_namespace_ref::b4_parser_class_name::location_type *yylocationp],
[[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
[yylocationp]],
b4_parse_param,
[[const char* msg], [msg]])[
@@ -127,7 +130,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
[ /// Build a parser object.
]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
:])[
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
#endif]b4_parse_param_cons[
@@ -144,7 +147,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
return ::yyparse (*this]b4_user_args[);
}
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
/*--------------------.
| Print this symbol. |
`--------------------*/
@@ -215,10 +218,10 @@ b4_namespace_close[
# Let glr.c believe that the user arguments include the parser itself.
m4_ifset([b4_parse_param],
[m4_pushdef([b4_parse_param],
m4_dquote([[[b4_namespace_ref::b4_parser_class_name& yyparser], [[yyparser]]],]
m4_defn([b4_parse_param])))],
[[b4_namespace_ref::b4_parser_class_name[& yyparser], [[yyparser]]],]
m4_defn([b4_parse_param]))],
[m4_pushdef([b4_parse_param],
[[[[b4_namespace_ref::b4_parser_class_name& yyparser], [[yyparser]]]]])
[[b4_namespace_ref::b4_parser_class_name[& yyparser], [[yyparser]]]])
])
m4_include(b4_pkgdatadir/[glr.c])
m4_popdef([b4_parse_param])
@@ -230,42 +233,16 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
/* C++ GLR parser skeleton written by Akim Demaille. */
#ifndef PARSER_HEADER_H
# define PARSER_HEADER_H
]b4_cpp_guard_open([b4_spec_defines_file])[
]b4_percent_code_get([[requires]])[
#include <string>
#include <iostream>
# include <string>
# include <iostream>
]b4_percent_define_ifdef([[location_type]], [],
[[#include "location.hh"]])[
[[# include "location.hh"]])[
/* Using locations. */
#define YYLSP_NEEDED ]b4_locations_flag[
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG ]b4_debug_flag[
#endif
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).begin = YYRHSLOC (Rhs, 1).begin; \
(Current).end = YYRHSLOC (Rhs, N).end; \
} \
else \
{ \
(Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
} \
while (/*CONSTCOND*/ 0)
#endif
]b4_YYDEBUG_define[
]b4_namespace_open[
/// A Bison parser.
@@ -273,7 +250,7 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
{
public:
/// Symbol semantic values.
#ifndef YYSTYPE
# ifndef ]b4_api_PREFIX[STYPE
]m4_ifdef([b4_stype],
[ union semantic_type
{
@@ -281,10 +258,10 @@ b4_user_stype
};],
[m4_if(b4_tag_seen_flag, 0,
[[ typedef int semantic_type;]],
[[ typedef YYSTYPE semantic_type;]])])[
#else
typedef YYSTYPE semantic_type;
#endif
[[ typedef ]b4_api_PREFIX[STYPE semantic_type;]])])[
# else
typedef ]b4_api_PREFIX[STYPE semantic_type;
# endif
/// Symbol locations.
typedef ]b4_percent_define_get([[location_type]],
[[location]])[ location_type;
@@ -325,7 +302,7 @@ b4_user_stype
virtual void error (const location_type& loc, const std::string& msg);
private:
#if YYDEBUG
# if ]b4_api_PREFIX[DEBUG
public:
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
@@ -345,7 +322,7 @@ b4_user_stype
/* Debugging. */
int yydebug_;
std::ostream* yycdebug_;
#endif
# endif
]b4_parse_param_vars[
};
@@ -354,16 +331,14 @@ b4_user_stype
b4_percent_define_flag_if([[global_tokens_and_yystype]],
[b4_token_defines(b4_tokens)])
[
#ifndef YYSTYPE
# define YYSTYPE ]b4_namespace_ref[::]b4_parser_class_name[::semantic_type
#ifndef ]b4_api_PREFIX[STYPE
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class_name[::semantic_type
#endif
#ifndef YYLTYPE
# define YYLTYPE ]b4_namespace_ref[::]b4_parser_class_name[::location_type
#ifndef ]b4_api_PREFIX[LTYPE
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class_name[::location_type
#endif
]b4_namespace_close[
]b4_percent_code_get([[provides]])[]dnl
[#endif /* ! defined PARSER_HEADER_H */]
m4_divert_pop(0)
]b4_percent_code_get([[provides]])[
]b4_cpp_guard_close([b4_spec_defines_file])[
]m4_divert_pop(0)
+32 -68
View File
@@ -55,25 +55,7 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
]b4_percent_define_ifdef([[location_type]], [],
[[#include "location.hh"]])[
]b4_null_define[
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG ]b4_debug_flag[
#endif
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE ]b4_error_verbose_flag[
#endif
/* Enabling the token table. */
#ifndef YYTOKEN_TABLE
# define YYTOKEN_TABLE ]b4_token_table[
#endif
]b4_YYDEBUG_define[
]b4_namespace_open[
@@ -82,7 +64,7 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
{
public:
/// Symbol semantic values.
#ifndef YYSTYPE
#ifndef ]b4_api_PREFIX[STYPE
]m4_ifdef([b4_stype],
[ union semantic_type
{
@@ -90,9 +72,9 @@ b4_user_stype
};],
[m4_if(b4_tag_seen_flag, 0,
[[ typedef int semantic_type;]],
[[ typedef YYSTYPE semantic_type;]])])[
[[ typedef ]b4_api_PREFIX[STYPE semantic_type;]])])[
#else
typedef YYSTYPE semantic_type;
typedef ]b4_api_PREFIX[STYPE semantic_type;
#endif
/// Symbol locations.
typedef ]b4_percent_define_get([[location_type]],
@@ -113,7 +95,7 @@ b4_user_stype
/// \returns 0 iff parsing succeeded.
virtual int parse ();
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
/// The current debugging stream.
std::ostream& debug_stream () const;
/// Set the current debugging stream.
@@ -138,7 +120,7 @@ b4_user_stype
/// \param tok the lookahead token.
virtual std::string yysyntax_error_ (int yystate, int tok);
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
@@ -211,17 +193,15 @@ b4_user_stype
/// For a rule, its LHS.
static const ]b4_int_type_for([b4_r1])[ yyr1_[];
/// For a rule, its RHS length.
static const ]b4_int_type_for([b4_r2])[ yyr2_[];
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/// For a symbol, its name in clear.
static const char* const yytname_[];
#endif]b4_error_verbose_if([
static const ]b4_int_type_for([b4_r2])[ yyr2_[]; ]b4_error_verbose_if([
/// Convert the symbol name \a n to a form suitable for a diagnostic.
static std::string yytnamerr_ (const char *n);])[
#if YYDEBUG
]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
/// For a symbol, its name in clear.
static const char* const yytname_[];
]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
/// A type to store symbol numbers and -1.
typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
/// A `-1'-separated list of the rules' RHS.
@@ -277,9 +257,9 @@ b4_user_stype
]b4_percent_define_flag_if([[global_tokens_and_yystype]],
[b4_token_defines(b4_tokens)
#ifndef YYSTYPE
#ifndef ]b4_api_PREFIX[STYPE
/* Redirection for backward compatibility. */
# define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
# define ]b4_api_PREFIX[STYPE b4_namespace_ref::b4_parser_class_name::semantic_type
#endif
])[
]b4_percent_code_get([[provides]])[
@@ -295,16 +275,18 @@ m4_if(b4_prefix, [yy], [],
#define yylex b4_prefix[]lex])[
/* First part of user declarations. */
]b4_user_pre_prologue
]b4_user_pre_prologue[
b4_defines_if([[
]b4_defines_if([[
#include "@basename(]b4_spec_defines_file[@)"]])[
/* User implementation prologue. */
]b4_user_post_prologue
b4_percent_code_get[]dnl
]b4_user_post_prologue[
]b4_percent_code_get[
[#ifndef YY_
]b4_null_define[
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
@@ -316,31 +298,14 @@ b4_percent_code_get[]dnl
# endif
#endif
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).begin = YYRHSLOC (Rhs, 1).begin; \
(Current).end = YYRHSLOC (Rhs, N).end; \
} \
else \
{ \
(Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
} \
while (false)
#endif
]b4_yylloc_default_define[
/* Suppress unused-variable warnings by "using" E. */
#define YYUSE(e) ((void) (e))
/* Enable debugging if requested. */
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
/* A pseudo ostream that takes yydebug_ into account. */
# define YYCDEBUG if (yydebug_) (*yycdebug_)
@@ -367,14 +332,14 @@ do { \
yystack_print_ (); \
} while (false)
#else /* !YYDEBUG */
#else /* !]b4_api_PREFIX[DEBUG */
# define YYCDEBUG if (false) std::cerr
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_REDUCE_PRINT(Rule)
# define YY_STACK_PRINT()
#endif /* !YYDEBUG */
#endif /* !]b4_api_PREFIX[DEBUG */
#define yyerrok (yyerrstatus_ = 0)
#define yyclearin (yychar = yyempty_)
@@ -427,7 +392,7 @@ do { \
/// Build a parser object.
]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
:])[
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
#endif]b4_parse_param_cons[
@@ -438,7 +403,7 @@ do { \
{
}
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
@@ -499,7 +464,7 @@ do { \
yylocation_stack_.pop (n);
}
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
std::ostream&
]b4_parser_class_name[::debug_stream () const
{
@@ -612,7 +577,7 @@ m4_popdef([b4_at_dollar])])dnl
{
YYCDEBUG << "Reading a token: ";
yychar = ]b4_c_function_call([yylex], [int],
[[YYSTYPE*], [&yylval]][]dnl
[b4_api_PREFIX[STYPE*], [&yylval]][]dnl
b4_locations_if([, [[location*], [&yylloc]]])dnl
m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
}
@@ -1027,7 +992,7 @@ b4_error_verbose_if([int yystate, int yytoken],
]b4_stos[
};
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
to YYLEX-NUM. */
const ]b4_int_type_for([b4_toknum])[
@@ -1051,7 +1016,7 @@ b4_error_verbose_if([int yystate, int yytoken],
]b4_r2[
};
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
const char*
@@ -1059,9 +1024,8 @@ b4_error_verbose_if([int yystate, int yytoken],
{
]b4_tname[
};
#endif
#if YYDEBUG
]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
const ]b4_parser_class_name[::rhs_number_type
]b4_parser_class_name[::yyrhs_[] =
@@ -1111,7 +1075,7 @@ b4_error_verbose_if([int yystate, int yytoken],
&]b4_rhs_value(yynrhs, yyi + 1)[,
&]b4_rhs_location(yynrhs, yyi + 1)[);
}
#endif // YYDEBUG
#endif // ]b4_api_PREFIX[DEBUG
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
]b4_parser_class_name[::token_number_type
+2 -2
View File
@@ -29,9 +29,9 @@ b4_copyright([Positions for Bison parsers in C++],
]b4_cpp_guard_open([b4_dir_prefix[]position.hh])[
# include <iostream>
# include <algorithm> // std::max
# include <iosfwd>
# include <string>
# include <algorithm>
]b4_null_define[
+101 -181
View File
@@ -158,9 +158,9 @@ m4_define([b4_rhs_location],
[(yylsp@{($2) - ($1)@})])
## ------------------ ##
## Parser variables. ##
## ------------------ ##
## -------------- ##
## Declarations. ##
## -------------- ##
# b4_declare_scanner_communication_variables
# ------------------------------------------
@@ -225,9 +225,73 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[
YYSIZE_T yyes_capacity;]])])
## --------------------------------------------------------- ##
## Defining symbol actions, e.g., printers and destructors. ##
## --------------------------------------------------------- ##
# b4_declare_yyparse_push_
# ------------------------
# Declaration of yyparse (and dependencies) when using the push parser
# (including in pull mode).
m4_define([b4_declare_yyparse_push_],
[[#ifndef YYPUSH_MORE_DEFINED
# define YYPUSH_MORE_DEFINED
enum { YYPUSH_MORE = 4 };
#endif
typedef struct ]b4_prefix[pstate ]b4_prefix[pstate;
]b4_pull_if([b4_c_function_decl([b4_prefix[parse]], [[int]], b4_parse_param)
])b4_c_function_decl([b4_prefix[push_parse]], [[int]],
[[b4_prefix[pstate *ps]], [[ps]]]b4_pure_if([,
[[[int pushed_char]], [[pushed_char]]],
[[b4_api_PREFIX[STYPE const *pushed_val]], [[pushed_val]]]b4_locations_if([,
[[b4_api_PREFIX[LTYPE const *pushed_loc]], [[pushed_loc]]]])])m4_ifset([b4_parse_param], [,
b4_parse_param]))
b4_pull_if([b4_c_function_decl([b4_prefix[pull_parse]], [[int]],
[[b4_prefix[pstate *ps]], [[ps]]]m4_ifset([b4_parse_param], [,
b4_parse_param]))])
b4_c_function_decl([b4_prefix[pstate_new]], [b4_prefix[pstate *]],
[[[void]], []])
b4_c_function_decl([b4_prefix[pstate_delete]], [[void]],
[[b4_prefix[pstate *ps]], [[ps]]])dnl
])
# b4_declare_yyparse_
# -------------------
# When not the push parser.
m4_define([b4_declare_yyparse_],
[[#ifdef YYPARSE_PARAM
]b4_c_function_decl(b4_prefix[parse], [int],
[[void *YYPARSE_PARAM], [YYPARSE_PARAM]])[
#else /* ! YYPARSE_PARAM */
]b4_c_function_decl(b4_prefix[parse], [int], b4_parse_param)[
#endif /* ! YYPARSE_PARAM */]dnl
])
# b4_declare_yyparse
# ------------------
m4_define([b4_declare_yyparse],
[b4_push_if([b4_declare_yyparse_push_],
[b4_declare_yyparse_])[]dnl
])
# b4_shared_declarations
# ----------------------
# Declaration that might either go into the header (if --defines)
# or open coded in the parser body.
m4_define([b4_shared_declarations],
[b4_cpp_guard_open([b4_spec_defines_file])[
]b4_declare_yydebug[
]b4_percent_code_get([[requires]])[
]b4_token_enums_defines(b4_tokens)[
]b4_declare_yylstype[
]b4_declare_yyparse[
]b4_percent_code_get([[provides]])[
]b4_cpp_guard_close([b4_spec_defines_file])[]dnl
])
## -------------- ##
## Output files. ##
## -------------- ##
# We do want M4 expansion after # for CPP macros.
m4_changecom()
@@ -248,7 +312,11 @@ b4_copyright([Bison implementation for Yacc-like parsers in C],
]b4_identification
b4_percent_code_get([[top]])[]dnl
m4_if(b4_prefix, [yy], [],
m4_if(b4_api_prefix, [yy], [],
[[/* Substitute the type names. */
#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
]m4_if(b4_prefix, [yy], [],
[[/* Substitute the variable and function names. */]b4_pull_if([[
#define yyparse ]b4_prefix[parse]])b4_push_if([[
#define yypush_parse ]b4_prefix[push_parse]b4_pull_if([[
@@ -261,19 +329,14 @@ m4_if(b4_prefix, [yy], [],
#define yylval ]b4_prefix[lval
#define yychar ]b4_prefix[char
#define yydebug ]b4_prefix[debug
#define yynerrs ]b4_prefix[nerrs
]b4_locations_if([[#define yylloc ]b4_prefix[lloc]])])[
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
#define yylloc ]b4_prefix[lloc]])])[
/* Copy the first part of user declarations. */
]b4_user_pre_prologue[
]b4_null_define[
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG ]b4_debug_flag[
#endif
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
@@ -282,66 +345,11 @@ m4_if(b4_prefix, [yy], [],
# define YYERROR_VERBOSE ]b4_error_verbose_flag[
#endif
/* Enabling the token table. */
#ifndef YYTOKEN_TABLE
# define YYTOKEN_TABLE ]b4_token_table[
#endif
/* In a future release of Bison, this section will be replaced
by #include "@basename(]b4_spec_defines_file[@)". */
]b4_shared_declarations[
]b4_percent_code_get([[requires]])[]dnl
b4_token_enums_defines(b4_tokens)[
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
]m4_ifdef([b4_stype],
[[typedef union ]b4_union_name[
{
]b4_user_stype[
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1]],
[m4_if(b4_tag_seen_flag, 0,
[[typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1]])])[
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif]b4_locations_if([[
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif]])b4_push_if([[
#ifndef YYPUSH_DECLS
# define YYPUSH_DECLS
struct yypstate;
typedef struct yypstate yypstate;
enum { YYPUSH_MORE = 4 };
]b4_pull_if([b4_c_function_decl([[yyparse]], [[int]], b4_parse_param)
])b4_c_function_decl([[yypush_parse]], [[int]],
[[[yypstate *yyps]], [[yyps]]]b4_pure_if([,
[[[int yypushed_char]], [[yypushed_char]]],
[[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
[[[YYLTYPE const *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [,
b4_parse_param]))
b4_pull_if([b4_c_function_decl([[yypull_parse]], [[int]],
[[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
b4_parse_param]))])
b4_c_function_decl([[yypstate_new]], [[yypstate *]], [[[void]], []])
b4_c_function_decl([[yypstate_delete]], [[void]],
[[[yypstate *yyps]], [[yyps]]])[
#endif]])
b4_percent_code_get([[provides]])[]dnl
[/* Copy the second part of user declarations. */
/* Copy the second part of user declarations. */
]b4_user_post_prologue
b4_percent_code_get[]dnl
@@ -491,8 +499,8 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
&& ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
|| (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
&& ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
@@ -582,7 +590,7 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
]b4_translate[
};
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
@@ -603,7 +611,7 @@ static const ]b4_int_type_for([b4_rline])[ yyrline[] =
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
@@ -737,31 +745,9 @@ while (YYID (0))
#define YYTERROR 1
#define YYERRCODE 256
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
]b4_yylloc_default_define[
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (YYID (N)) \
{ \
(Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
(Current).last_line = YYRHSLOC (Rhs, N).last_line; \
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
} \
else \
{ \
(Current).first_line = (Current).last_line = \
YYRHSLOC (Rhs, 0).last_line; \
(Current).first_column = (Current).last_column = \
YYRHSLOC (Rhs, 0).last_column; \
} \
while (YYID (0))
#endif]b4_locations_if([[
]b4_locations_if([[
/* YY_LOCATION_PRINT -- Print the location on the stream.
@@ -769,7 +755,7 @@ while (YYID (0))
we won't break user code: when these are the locations we know. */
#ifndef YY_LOCATION_PRINT
# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
# define YY_LOCATION_PRINT(File, Loc) \
fprintf (File, "%d.%d-%d.%d", \
(Loc).first_line, (Loc).first_column, \
@@ -796,7 +782,7 @@ while (YYID (0))
#endif
/* Enable debugging if requested. */
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
@@ -883,12 +869,12 @@ do { \
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
#else /* !YYDEBUG */
#else /* !]b4_api_PREFIX[DEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
#endif /* !]b4_api_PREFIX[DEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
@@ -919,7 +905,7 @@ int yydebug;
required. Return 1 if memory is exhausted. */
static int
yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
char const *yydebug_prefix,
char const *yydebug_suffix,
#endif
@@ -1025,7 +1011,7 @@ do { \
the parser stacks to try to find a new initial context in which the
current lookahead is syntactically acceptable. If it fails to find
such a context, it discards the lookahead. */
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
# define YY_LAC_DISCARD(Event) \
do { \
if (yy_lac_established) \
@@ -1128,7 +1114,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
else
{
if (yy_lac_stack_realloc (yyes_capacity, 1,
#if YYDEBUG
#if ]b4_api_PREFIX[DEBUG
" (", ")",
#endif
yyes, yyesa, &yyesp, yyes_prev))
@@ -1335,7 +1321,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
yysize = yysize1;
}
}]b4_lac_if([[
# if YYDEBUG
# if ]b4_api_PREFIX[DEBUG
else if (yydebug)
YYFPRINTF (stderr, "No expected tokens.\n");
# endif]])[
@@ -1392,20 +1378,12 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
}
#endif /* YYERROR_VERBOSE */
]b4_yydestruct_generate([b4_c_function_def])b4_push_if([], [[
]b4_yydestruct_generate([b4_c_function_def])[
/* Prevent warnings from -Wmissing-prototypes. */
#ifdef YYPARSE_PARAM
]b4_c_function_decl([yyparse], [int],
[[void *YYPARSE_PARAM], [YYPARSE_PARAM]])[
#else /* ! YYPARSE_PARAM */
]b4_c_function_decl([yyparse], [int], b4_parse_param)[
#endif /* ! YYPARSE_PARAM */]])b4_pure_if([], [
]b4_pure_if([], [
b4_declare_scanner_communication_variables])[]b4_push_if([[
struct yypstate
{]b4_declare_parser_state_variables[
/* Used to determine if this is the first time this instance has
@@ -1586,7 +1564,7 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[
yyvsp = yyvs;]b4_locations_if([[
yylsp = yyls;
#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
#if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
/* Initialize the default location before parsing starts. */
yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
@@ -2072,66 +2050,8 @@ yypushreturn:]])[
b4_defines_if(
[@output(b4_spec_defines_file@)@
b4_copyright([Bison interface for Yacc-like parsers in C],
[1984, 1989-1990, 2000-2012])
[1984, 1989-1990, 2000-2012])[
b4_percent_code_get([[requires]])[]dnl
b4_token_enums_defines(b4_tokens)
[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
]m4_ifdef([b4_stype],
[[typedef union ]b4_union_name[
{
]b4_user_stype[
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1]],
[m4_if(b4_tag_seen_flag, 0,
[[typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1]])])[
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
]b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval;]])
b4_locations_if(
[#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
]b4_pure_if([], [[extern YYLTYPE ]b4_prefix[lloc;]])
)dnl b4_locations_if
b4_push_if([[
#ifndef YYPUSH_DECLS
# define YYPUSH_DECLS
struct ]b4_prefix[pstate;
typedef struct ]b4_prefix[pstate ]b4_prefix[pstate;
enum { YYPUSH_MORE = 4 };
]b4_pull_if([b4_c_function_decl([b4_prefix[parse]], [[int]], b4_parse_param)
])b4_c_function_decl([b4_prefix[push_parse]], [[int]],
[[b4_prefix[pstate *yyps]], [[yyps]]]b4_pure_if([,
[[[int yypushed_char]], [[yypushed_char]]],
[[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
[[[YYLTYPE const *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [,
b4_parse_param]))
b4_pull_if([b4_c_function_decl([b4_prefix[pull_parse]], [[int]],
[[b4_prefix[pstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
b4_parse_param]))])
b4_c_function_decl([b4_prefix[pstate_new]], [b4_prefix[pstate *]],
[[[void]], []])
b4_c_function_decl([b4_prefix[pstate_delete]], [[void]],
[[b4_prefix[pstate *yyps]], [[yyps]]])[
#endif
]])
b4_percent_code_get([[provides]])[]dnl
])dnl b4_defines_if
]b4_shared_declarations[
]])dnl b4_defines_if
m4_divert_pop(0)
+1 -1
View File
@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AM_MAKEINFOFLAGS = --no-split
info_TEXINFOS = bison.texinfo
info_TEXINFOS = bison.texi
bison_TEXINFOS = $(srcdir)/cross-options.texi gpl-3.0.texi fdl.texi
CLEANFILES = bison.fns
+151 -67
View File
@@ -5074,9 +5074,11 @@ default location or at the location specified by @var{qualifier}.
@end deffn
@deffn {Directive} %debug
In the parser implementation file, define the macro @code{YYDEBUG} to
1 if it is not already defined, so that the debugging facilities are
compiled. @xref{Tracing, ,Tracing Your Parser}.
In the parser implementation file, define the macro @code{YYDEBUG} (or
@code{@var{prefix}DEBUG} with @samp{%define api.prefix @var{prefix}}), see
@ref{Multiple Parsers, ,Multiple Parsers in the Same Program}) to 1 if it is
not already defined, so that the debugging facilities are compiled.
@xref{Tracing, ,Tracing Your Parser}.
@end deffn
@deffn {Directive} %define @var{variable}
@@ -5154,22 +5156,6 @@ grammar does not use it, using @samp{%locations} allows for more
accurate syntax error messages.
@end deffn
@deffn {Directive} %name-prefix "@var{prefix}"
Rename the external symbols used in the parser so that they start with
@var{prefix} instead of @samp{yy}. The precise list of symbols renamed
in C parsers
is @code{yyparse}, @code{yylex}, @code{yyerror}, @code{yynerrs},
@code{yylval}, @code{yychar}, @code{yydebug}, and
(if locations are used) @code{yylloc}. If you use a push parser,
@code{yypush_parse}, @code{yypull_parse}, @code{yypstate},
@code{yypstate_new} and @code{yypstate_delete} will
also be renamed. For example, if you use @samp{%name-prefix "c_"}, the
names become @code{c_parse}, @code{c_lex}, and so on.
For C++ parsers, see the @code{%define namespace} documentation in this
section.
@xref{Multiple Parsers, ,Multiple Parsers in the Same Program}.
@end deffn
@ifset defaultprec
@deffn {Directive} %no-default-prec
Do not assign a precedence to rules lacking an explicit @code{%prec}
@@ -5317,8 +5303,25 @@ Unaccepted @var{variable}s produce an error.
Some of the accepted @var{variable}s are:
@itemize @bullet
@c ================================================== api.prefix
@item @code{api.prefix}
@findex %define api.prefix
@itemize @bullet
@item Language(s): All
@item Purpose: Rename exported symbols
@xref{Multiple Parsers, ,Multiple Parsers in the Same Program}.
@item Accepted Values: String
@item Default Value: @code{yy}
@item History: introduced in Bison 2.6
@end itemize
@c ================================================== api.pure
@item api.pure
@item @code{api.pure}
@findex %define api.pure
@itemize @bullet
@@ -5332,7 +5335,9 @@ Some of the accepted @var{variable}s are:
@item Default Value: @code{false}
@end itemize
@item api.push-pull
@c ================================================== api.push-pull
@item @code{api.push-pull}
@findex %define api.push-pull
@itemize @bullet
@@ -5350,7 +5355,7 @@ More user feedback will help to stabilize it.)
@c ================================================== lr.default-reductions
@item lr.default-reductions
@item @code{lr.default-reductions}
@findex %define lr.default-reductions
@itemize @bullet
@@ -5371,7 +5376,7 @@ feedback will help to stabilize it.)
@c ============================================ lr.keep-unreachable-states
@item lr.keep-unreachable-states
@item @code{lr.keep-unreachable-states}
@findex %define lr.keep-unreachable-states
@itemize @bullet
@@ -5384,7 +5389,7 @@ remain in the parser tables. @xref{Unreachable States}.
@c ================================================== lr.type
@item lr.type
@item @code{lr.type}
@findex %define lr.type
@itemize @bullet
@@ -5399,7 +5404,9 @@ More user feedback will help to stabilize it.)
@item Default Value: @code{lalr}
@end itemize
@item namespace
@c ================================================== namespace
@item @code{namespace}
@findex %define namespace
@itemize
@@ -5452,7 +5459,7 @@ The parser namespace is @code{foo} and @code{yylex} is referenced as
@end itemize
@c ================================================== parse.lac
@item parse.lac
@item @code{parse.lac}
@findex %define parse.lac
@itemize
@@ -5585,34 +5592,88 @@ of the standard Bison skeletons.
@section Multiple Parsers in the Same Program
Most programs that use Bison parse only one language and therefore contain
only one Bison parser. But what if you want to parse more than one
language with the same program? Then you need to avoid a name conflict
between different definitions of @code{yyparse}, @code{yylval}, and so on.
only one Bison parser. But what if you want to parse more than one language
with the same program? Then you need to avoid name conflicts between
different definitions of functions and variables such as @code{yyparse},
@code{yylval}. To use different parsers from the same compilation unit, you
also need to avoid conflicts on types and macros (e.g., @code{YYSTYPE})
exported in the generated header.
The easy way to do this is to use the option @samp{-p @var{prefix}}
(@pxref{Invocation, ,Invoking Bison}). This renames the interface
functions and variables of the Bison parser to start with @var{prefix}
instead of @samp{yy}. You can use this to give each parser distinct
names that do not conflict.
The easy way to do this is to define the @code{%define} variable
@code{api.prefix}. With different @code{api.prefix}s it is guaranteed that
headers do not conflict when included together, and that compiled objects
can be linked together too. Specifying @samp{%define api.prefix
@var{prefix}} (or passing the option @samp{-Dapi.prefix=@var{prefix}}, see
@ref{Invocation, ,Invoking Bison}) renames the interface functions and
variables of the Bison parser to start with @var{prefix} instead of
@samp{yy}, and all the macros to start by @var{PREFIX} (i.e., @var{prefix}
upper-cased) instead of @samp{YY}.
The precise list of symbols renamed is @code{yyparse}, @code{yylex},
@code{yyerror}, @code{yynerrs}, @code{yylval}, @code{yylloc},
@code{yychar} and @code{yydebug}. If you use a push parser,
@code{yypush_parse}, @code{yypull_parse}, @code{yypstate},
@code{yypstate_new} and @code{yypstate_delete} will also be renamed.
For example, if you use @samp{-p c}, the names become @code{cparse},
@code{clex}, and so on.
The renamed symbols include @code{yyparse}, @code{yylex}, @code{yyerror},
@code{yynerrs}, @code{yylval}, @code{yylloc}, @code{yychar} and
@code{yydebug}. If you use a push parser, @code{yypush_parse},
@code{yypull_parse}, @code{yypstate}, @code{yypstate_new} and
@code{yypstate_delete} will also be renamed. The renamed macros include
@code{YYSTYPE}, @code{YYLTYPE}, and @code{YYDEBUG}, which is treated
specifically --- more about this below.
@strong{All the other variables and macros associated with Bison are not
renamed.} These others are not global; there is no conflict if the same
name is used in different parsers. For example, @code{YYSTYPE} is not
renamed, but defining this in different ways in different parsers causes
no trouble (@pxref{Value Type, ,Data Types of Semantic Values}).
For example, if you use @samp{%define api.prefix c}, the names become
@code{cparse}, @code{clex}, @dots{}, @code{CSTYPE}, @code{CLTYPE}, and so
on.
The @samp{-p} option works by adding macro definitions to the
beginning of the parser implementation file, defining @code{yyparse}
as @code{@var{prefix}parse}, and so on. This effectively substitutes
one name for the other in the entire parser implementation file.
The @code{%define} variable @code{api.prefix} works in two different ways.
In the implementation file, it works by adding macro definitions to the
beginning of the parser implementation file, defining @code{yyparse} as
@code{@var{prefix}parse}, and so on:
@example
#define YYSTYPE CTYPE
#define yyparse cparse
#define yylval clval
...
YYSTYPE yylval;
int yyparse (void);
@end example
This effectively substitutes one name for the other in the entire parser
implementation file, thus the ``original'' names (@code{yylex},
@code{YYSTYPE}, @dots{}) are also usable in the parser implementation file.
However, in the parser header file, the symbols are defined renamed, for
instance:
@example
extern CSTYPE clval;
int cparse (void);
@end example
The macro @code{YYDEBUG} is commonly used to enable the tracing support in
parsers. To comply with this tradition, when @code{api.prefix} is used,
@code{YYDEBUG} (not renamed) is used as a default value:
@example
/* Enabling traces. */
#ifndef CDEBUG
# if defined YYDEBUG
# if YYDEBUG
# define CDEBUG 1
# else
# define CDEBUG 0
# endif
# else
# define CDEBUG 0
# endif
#endif
#if CDEBUG
extern int cdebug;
#endif
@end example
@sp 2
Prior to Bison 2.6, a feature similar to @code{api.prefix} was provided by
the obsolete directive @code{%name-prefix} (@pxref{Table of Symbols, ,Bison
Symbols}) and the option @code{--name-prefix} (@pxref{Bison Options}).
@node Interface
@chapter Parser C-Language Interface
@@ -5729,9 +5790,9 @@ function is available if either the @code{%define api.push-pull push} or
@xref{Push Decl, ,A Push Parser}.
@deftypefun int yypush_parse (yypstate *yyps)
The value returned by @code{yypush_parse} is the same as for yyparse with the
following exception. @code{yypush_parse} will return YYPUSH_MORE if more input
is required to finish parsing the grammar.
The value returned by @code{yypush_parse} is the same as for yyparse with
the following exception: it returns @code{YYPUSH_MORE} if more input is
required to finish parsing the grammar.
@end deftypefun
@node Pull Parser Function
@@ -6011,7 +6072,7 @@ For instance:
@end example
@noindent
results in the following signature:
results in the following signatures:
@example
int yylex (int *nastiness);
@@ -8437,18 +8498,24 @@ parser. This is compliant with POSIX Yacc. You could use
YYDEBUG 1} in the prologue of the grammar file (@pxref{Prologue, , The
Prologue}).
@item the option @option{-t}, @option{--debug}
Use the @samp{-t} option when you run Bison (@pxref{Invocation,
,Invoking Bison}). This is POSIX compliant too.
If the @code{%define} variable @code{api.prefix} is used (@pxref{Multiple
Parsers, ,Multiple Parsers in the Same Program}), for instance @samp{%define
api.prefix x}, then if @code{CDEBUG} is defined, its value controls the
tracing feature (enabled iff nonzero); otherwise tracing is enabled iff
@code{YYDEBUG} is nonzero.
@item the option @option{-t} (POSIX Yacc compliant)
@itemx the option @option{--debug} (Bison extension)
Use the @samp{-t} option when you run Bison (@pxref{Invocation, ,Invoking
Bison}). With @samp{%define api.prefix c}, it defines @code{CDEBUG} to 1,
otherwise it defines @code{YYDEBUG} to 1.
@item the directive @samp{%debug}
@findex %debug
Add the @code{%debug} directive (@pxref{Decl Summary, ,Bison
Declaration Summary}). This is a Bison extension, which will prove
useful when Bison will output parsers for languages that don't use a
preprocessor. Unless POSIX and Yacc portability matter to
you, this is
the preferred solution.
Add the @code{%debug} directive (@pxref{Decl Summary, ,Bison Declaration
Summary}). This is a Bison extension, especially useful for languages that
don't use a preprocessor. Unless POSIX and Yacc portability matter to you,
this is the preferred solution.
@end table
We suggest that you always enable the debug option so that debugging is
@@ -8924,8 +8991,9 @@ Pretend that @code{%locations} was specified. @xref{Decl Summary}.
@item -p @var{prefix}
@itemx --name-prefix=@var{prefix}
Pretend that @code{%name-prefix "@var{prefix}"} was specified.
@xref{Decl Summary}.
Pretend that @code{%name-prefix "@var{prefix}"} was specified (@pxref{Decl
Summary}). Obsoleted by @code{-Dapi.prefix=@var{prefix}}. @xref{Multiple
Parsers, ,Multiple Parsers in the Same Program}.
@item -l
@itemx --no-lines
@@ -11054,9 +11122,24 @@ function is applied to the two semantic values to get a single result.
@end deffn
@deffn {Directive} %name-prefix "@var{prefix}"
Bison declaration to rename the external symbols. @xref{Decl Summary}.
Obsoleted by the @code{%define} variable @code{api.prefix} (@pxref{Multiple
Parsers, ,Multiple Parsers in the Same Program}).
Rename the external symbols (variables and functions) used in the parser so
that they start with @var{prefix} instead of @samp{yy}. Contrary to
@code{api.prefix}, do no rename types and macros.
The precise list of symbols renamed in C parsers is @code{yyparse},
@code{yylex}, @code{yyerror}, @code{yynerrs}, @code{yylval}, @code{yychar},
@code{yydebug}, and (if locations are used) @code{yylloc}. If you use a
push parser, @code{yypush_parse}, @code{yypull_parse}, @code{yypstate},
@code{yypstate_new} and @code{yypstate_delete} will also be renamed. For
example, if you use @samp{%name-prefix "c_"}, the names become
@code{c_parse}, @code{c_lex}, and so on. For C++ parsers, see the
@code{%define namespace} documentation in this section.
@end deffn
@ifset defaultprec
@deffn {Directive} %no-default-prec
Do not assign a precedence to rules that lack an explicit @samp{%prec}
@@ -11216,7 +11299,8 @@ Reporting Function @code{yyerror}}.
An obsolete macro that you define with @code{#define} in the prologue
to request verbose, specific error message strings
when @code{yyerror} is called. It doesn't matter what definition you
use for @code{YYERROR_VERBOSE}, just whether you define it. Using
use for @code{YYERROR_VERBOSE}, just whether you define it.
Supported by the C skeletons only; using
@code{%error-verbose} is preferred. @xref{Error Reporting}.
@end deffn
-3
View File
@@ -1,6 +1,3 @@
A directory of tools provided to people using CVS Bison. None of
these is distributed.
* bench.pl
A primitive Perl script to run benches. Currently its only bench is
the usual calculator: it has a lightweight processing part (but not
+2 -2
View File
@@ -28,7 +28,7 @@ $(BISON): $(BISON_IN)
## Extracting. ##
## ------------ ##
doc = $(top_srcdir)/doc/bison.texinfo
doc = $(top_srcdir)/doc/bison.texi
extexi = $(top_srcdir)/examples/extexi
# Extract in src.
$(srcdir)/calc.stamp: $(doc) $(extexi)
@@ -36,7 +36,7 @@ $(srcdir)/calc.stamp: $(doc) $(extexi)
$(AM_V_at)touch $@.tmp
$(AM_V_at)cd $(srcdir) && \
$(AWK) -f ../extexi -v VERSION="$(VERSION)" \
../../doc/bison.texinfo -- calc++-parser.yy \
../../doc/bison.texi -- calc++-parser.yy \
calc++-scanner.ll calc++.cc calc++-driver.hh calc++-driver.cc
$(AM_V_at)mv $@.tmp $@
+1 -1
Submodule gnulib updated: 338dd5d436...cabce6b8f2
+3
View File
@@ -0,0 +1,3 @@
/lock.c
/lock.h
/threadlib.c
+3 -2
View File
@@ -34,6 +34,7 @@
/fprintf-posix.m4
/frexp.m4
/frexpl.m4
/fseterr.m4
/fstat.m4
/getdtablesize.m4
/getopt.m4
@@ -95,6 +96,7 @@
/multiarch.m4
/nls.m4
/nocrash.m4
/off_t.m4
/open.m4
/pathmax.m4
/perror.m4
@@ -150,6 +152,7 @@
/sys_ioctl_h.m4
/sys_socket_h.m4
/sys_stat_h.m4
/sys_types_h.m4
/sys_wait_h.m4
/sysexits.m4
/threadlib.m4
@@ -176,5 +179,3 @@
/xalloc.m4
/xsize.m4
/xstrndup.m4
/off_t.m4
/sys_types_h.m4
+4 -3
View File
@@ -311,10 +311,11 @@ Parser:\n\
-S, --skeleton=FILE specify the skeleton to use\n\
-t, --debug instrument the parser for debugging\n\
--locations enable location support\n\
-D, --define=NAME[=VALUE] similar to `%define NAME \"VALUE\"'\n\
-F, --force-define=NAME[=VALUE] override `%define NAME \"VALUE\"'\n\
-D, --define=NAME[=VALUE] similar to '%define NAME \"VALUE\"'\n\
-F, --force-define=NAME[=VALUE] override '%define NAME \"VALUE\"'\n\
-p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
-l, --no-lines don't generate `#line' directives\n\
deprecated by '-Dapi.prefix=PREFIX'\n\
-l, --no-lines don't generate '#line' directives\n\
-k, --token-table include a table of token names\n\
\n\
"), stdout);
+1 -1
View File
@@ -142,7 +142,6 @@ escaped_output (FILE *out, char const *string)
static void
prepare_symbols (void)
{
MUSCLE_INSERT_BOOL ("token_table", token_table_flag);
MUSCLE_INSERT_INT ("tokens_number", ntokens);
MUSCLE_INSERT_INT ("nterms_number", nvars);
MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
@@ -624,6 +623,7 @@ prepare (void)
MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser);
MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);
MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen);
MUSCLE_INSERT_BOOL ("token_table_flag", token_table_flag);
MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag);
MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag);
+155 -339
View File
File diff suppressed because it is too large Load Diff
+27 -7
View File
@@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 2.5.1_rc2. */
/* A Bison parser, made by GNU Bison 2.5.1.19-ced26-dirty. */
/* Bison interface for Yacc-like parsers in C
@@ -30,6 +30,15 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef GRAM__________SRC_PARSE_GRAM_H
# define GRAM__________SRC_PARSE_GRAM_H
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int gram_debug;
#endif
/* Tokens. */
#ifndef YYTOKENTYPE
@@ -155,12 +164,11 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 2072 of yacc.c */
/* Line 2063 of yacc.c */
#line 114 "parse-gram.y"
symbol *symbol;
@@ -175,16 +183,14 @@ typedef union YYSTYPE
/* Line 2072 of yacc.c */
#line 180 "parse-gram.h"
/* Line 2063 of yacc.c */
#line 188 "parse-gram.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
@@ -198,5 +204,19 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1
#endif
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int gram_parse (void *YYPARSE_PARAM);
#else
int gram_parse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int gram_parse (void);
#else
int gram_parse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !GRAM__________SRC_PARSE_GRAM_H */
+5 -5
View File
@@ -73,23 +73,23 @@ check-local: atconfig atlocal $(TESTSUITE)
check_SCRIPTS = bison
# Run the test suite on the *installed* tree.
installcheck-local:
installcheck-local: atconfig atlocal $(TESTSUITE)
$(TESTSUITE) AUTOTEST_PATH="$(bindir)" $(TESTSUITEFLAGS)
# Be real mean with it.
.PHONY: maintainer-check-g++
maintainer-check-g++: $(TESTSUITE)
maintainer-check-g++: atconfig atlocal $(TESTSUITE)
$(TESTSUITE) $(TESTSUITEFLAGS) --compile-c-with-cxx
.PHONY: maintainer-check-posix
maintainer-check-posix: $(TESTSUITE)
maintainer-check-posix: atconfig atlocal $(TESTSUITE)
$(TESTSUITE) $(TESTSUITEFLAGS) POSIXLY_CORRECT=1 _POSIX2_VERSION=200112
.PHONY: maintainer-check-valgrind
maintainer-check-valgrind: $(TESTSUITE)
maintainer-check-valgrind: atconfig atlocal $(TESTSUITE)
test -z '$(VALGRIND)' || \
$(TESTSUITE) $(TESTSUITEFLAGS) \
PREBISON='$(VALGRIND) -q' PREPARSER='$(VALGRIND) -q' \
PREBISON='$(VALGRIND_PREBISON)' PREPARSER='$(VALGRIND) -q' \
VALGRIND_OPTS='--leak-check=full --show-reachable=yes'
.PHONY: maintainer-check
+148 -286
View File
@@ -28,14 +28,13 @@ AT_SETUP([Mid-rule actions])
# instead of being attached to the empty rule dedicated to this
# action.
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%error-verbose
%debug
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%%
exp: { putchar ('0'); }
@@ -51,28 +50,15 @@ exp: { putchar ('0'); }
{ putchar ('\n'); }
;
%%
static int
yylex (void)
{
static char const input[] = "123456789";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
return input[toknum++];
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["123456789"])[
int
main (void)
{
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-d -v -o input.c input.y])
AT_COMPILE([input])
@@ -92,14 +78,13 @@ AT_CLEANUP
AT_SETUP([Exotic Dollars])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%error-verbose
%debug
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
# define USE(Var)
%}
@@ -130,21 +115,8 @@ sum_of_the_five_previous_values:
;
%%
static int
yylex (void)
{
static int called;
if (called++)
abort ();
return EOF;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
int
main (void)
{
@@ -164,9 +136,9 @@ AT_PARSER_CHECK([./input], 0,
AT_DATA_GRAMMAR([[input.y]],
[[
%{
# include <stdio.h>
static int yylex (void);
static void yyerror (char const *msg);
#include <stdio.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
typedef struct { int val; } stype;
# define YYSTYPE stype
%}
@@ -178,19 +150,8 @@ two: { $$.val = 2; } ;
sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ;
%%
static int
yylex (void)
{
return 0;
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
int
main (void)
{
@@ -204,6 +165,7 @@ AT_PARSER_CHECK([[./input]], [[0]],
[[6
]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -212,11 +174,12 @@ AT_CLEANUP
## Printers and Destructors. ##
## -------------------------- ##
# _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4, BISON-DIRECTIVE, UNION-FLAG)
# -----------------------------------------------------------------------------
# _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4,
# BISON-DIRECTIVE, UNION-FLAG)
# -------------------------------------------------------------
m4_define([_AT_CHECK_PRINTER_AND_DESTRUCTOR],
[# Make sure complex $n work.
m4_if([$1$2$3], $[1]$[2]$[3], [],
m4_if([$1$2$3$4], $[1]$[2]$[3]$[4], [],
[m4_fatal([$0: Invalid arguments: $@])])dnl
# Be sure to pass all the %directives to this macro to have correct
@@ -231,21 +194,24 @@ AT_DATA_GRAMMAR([[input.y]],
#define YYINITDEPTH 10
#define YYMAXDEPTH 10
]AT_LALR1_CC_IF(
[#define RANGE(Location) (Location).begin.line, (Location).end.line],
[#define RANGE(Location) (Location).first_line, (Location).last_line])
[}
#define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
[(Location).first_line, (Location).last_line])[
$5]
m4_ifval([$6], [%union
/* Display the symbol type Symbol. */
#define V(Symbol, Value, Location, Sep) \
fprintf (stderr, #Symbol " (%d@%d-%d)" Sep, Value, RANGE(Location))
}
$5
]m4_ifval([$6], [%union
{
int ival;
}])
AT_LALR1_CC_IF([%define global_tokens_and_yystype])
m4_ifval([$6], [[%code provides {]], [[%code {]])
AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])
[static int yylex (]AT_LEX_FORMALS[);
]AT_LALR1_CC_IF([], [static void yyerror (const char *msg);])
AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[
]AT_YYLEX_DECLARE[
]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE])
[}
]m4_ifval([$6], [%type <ival> '(' 'x' 'y' ')' ';' thing line input END])[
@@ -259,28 +225,28 @@ AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])
input line thing 'x' 'y'
%destructor
{ printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
input
%destructor
{ printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
line
%destructor
{ printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
thing
%destructor
{ printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
'x'
%destructor
{ printf ("Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
'y'
%token END 0
%destructor
{ printf ("Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
END
%%
@@ -295,14 +261,15 @@ input:
/* Nothing. */
{
$$ = 0;
printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
V(input, $$, @$, ": /* Nothing */\n");
}
| line input /* Right recursive to load the stack so that popping at
END can be exercised. */
{
$$ = 2;
printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
V(input, $$, @$, ": ");
V(line, $1, @1, " ");
V(input, $2, @2, "\n");
}
;
@@ -310,28 +277,36 @@ line:
thing thing thing ';'
{
$$ = $1;
printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
$3, RANGE (@3), $4, RANGE (@4));
V(line, $$, @$, ": ");
V(thing, $1, @1, " ");
V(thing, $2, @2, " ");
V(thing, $3, @3, " ");
V(;, $4, @4, "\n");
}
| '(' thing thing ')'
{
$$ = $1;
printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
$3, RANGE (@3), $4, RANGE (@4));
V(line, $$, @$, ": ");
V('(', $1, @1, " ");
V(thing, $2, @2, " ");
V(thing, $3, @3, " ");
V(')', $4, @4, "\n");
}
| '(' thing ')'
{
$$ = $1;
printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
V(line, $$, @$, ": ");
V('(', $1, @1, " ");
V(thing, $2, @2, " ");
V(')', $3, @3, "\n");
}
| '(' error ')'
{
$$ = -1;
printf ("line (%d@%d-%d): '(' (%d@%d-%d) error (@%d-%d) ')' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), RANGE (@2), $3, RANGE (@3));
V(line, $$, @$, ": ");
V('(', $1, @1, " ");
fprintf (stderr, "error (@%d-%d) ", RANGE(@2));
V(')', $3, @3, "\n");
}
;
@@ -339,48 +314,35 @@ thing:
'x'
{
$$ = $1;
printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1));
V(thing, $$, @$, ": ");
V('x', $1, @1, "\n");
}
;
%%
/* Alias to ARGV[1]. */
const char *source = YY_NULL;
static int
yylex (]AT_LEX_FORMALS[)
]AT_YYERROR_DEFINE[
static
]AT_YYLEX_PROTOTYPE[
{
static unsigned int counter = 0;
int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
/* As in BASIC, line numbers go from 10 to 10. */
]AT_LALR1_CC_IF(
[ AT_LOC.begin.line = AT_LOC.begin.column = 10 * c;
AT_LOC.end.line = AT_LOC.end.column = AT_LOC.begin.line + 9;
],
[ AT_LOC.first_line = AT_LOC.first_column = 10 * c;
AT_LOC.last_line = AT_LOC.last_column = AT_LOC.first_line + 9;
])[
if (! (0 <= c && c <= strlen (source)))
abort ();
]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
assert (0 <= c && c <= strlen (source));
if (source[c])
printf ("sending: '%c'", source[c]);
fprintf (stderr, "sending: '%c'", source[c]);
else
printf ("sending: END");
printf (" (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
fprintf (stderr, "sending: END");
fprintf (stderr, " (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
return source[c];
}
]AT_LALR1_CC_IF(
[/* A C++ error reporting function. */
void
yy::parser::error (const location& l, const std::string& m)
{
printf ("%d-%d: %s\n", RANGE (l), m.c_str());
}
static bool yydebug;
[static bool yydebug;
int
yyparse ()
{
@@ -388,12 +350,7 @@ yyparse ()
parser.set_debug_level (yydebug);
return parser.parse ();
}
],
[static void
yyerror (const char *msg)
{
printf ("%d-%d: %s\n", RANGE (yylloc), msg);
}])[
])[
int
main (int argc, const char *argv[])
@@ -405,9 +362,9 @@ main (int argc, const char *argv[])
status = yyparse ();
switch (status)
{
case 0: printf ("Successful parse.\n"); break;
case 1: printf ("Parsing FAILED.\n"); break;
default: printf ("Parsing FAILED (status %d).\n", status); break;
case 0: fprintf (stderr, "Successful parse.\n"); break;
case 1: fprintf (stderr, "Parsing FAILED.\n"); break;
default: fprintf (stderr, "Parsing FAILED (status %d).\n", status); break;
}
return status;
}
@@ -421,7 +378,7 @@ AT_FULL_COMPILE([input])
# I.e., epsilon-reductions, as in "(x)" which ends by reducing
# an empty "line" nterm.
# FIXME: This location is not satisfying. Depend on the lookahead?
AT_PARSER_CHECK([./input '(x)'], 0,
AT_PARSER_CHECK([./input '(x)'], 0, [],
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
@@ -440,10 +397,10 @@ Successful parse.
# ---------------------------------
# '(y)' is an error, but can be recovered from. But what's the location
# of the error itself ('y'), and of the resulting reduction ('(error)').
AT_PARSER_CHECK([./input '(y)'], 0,
AT_PARSER_CHECK([./input '(y)'], 0, [],
[[sending: '(' (0@0-9)
sending: 'y' (1@10-19)
10-19: syntax error, unexpected 'y', expecting 'x'
10.10-19.18: syntax error, unexpected 'y', expecting 'x'
Freeing token 'y' (1@10-19)
sending: ')' (2@20-29)
line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
@@ -470,14 +427,14 @@ Successful parse.
# '(', 'x', ')',
# '(', 'x', ')',
# 'y'
AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1,
AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1, [],
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
sending: 'x' (2@20-29)
thing (2@20-29): 'x' (2@20-29)
sending: 'x' (3@30-39)
30-39: syntax error, unexpected 'x', expecting ')'
30.30-39.38: syntax error, unexpected 'x', expecting ')'
Freeing nterm thing (2@20-29)
Freeing nterm thing (1@10-19)
Freeing token 'x' (3@30-39)
@@ -502,7 +459,7 @@ input (0@129-129): /* Nothing */
input (2@100-129): line (10@100-129) input (0@129-129)
input (2@70-129): line (7@70-99) input (2@100-129)
input (2@0-129): line (-1@0-69) input (2@70-129)
130-139: syntax error, unexpected 'y', expecting END
130.130-139.138: syntax error, unexpected 'y', expecting END
Freeing nterm input (2@0-129)
Freeing token 'y' (13@130-139)
Parsing FAILED.
@@ -518,7 +475,7 @@ Parsing FAILED.
# '(', 'x', ')',
# '(', 'x', ')',
# 'x'
AT_PARSER_CHECK([./input '(x)(x)x'], 1,
AT_PARSER_CHECK([./input '(x)(x)x'], 1, [],
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
@@ -532,7 +489,7 @@ line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
sending: 'x' (6@60-69)
thing (6@60-69): 'x' (6@60-69)
sending: END (7@70-79)
70-79: syntax error, unexpected END, expecting 'x'
70.70-79.78: syntax error, unexpected END, expecting 'x'
Freeing nterm thing (6@60-69)
Freeing nterm line (3@30-59)
Freeing nterm line (0@0-29)
@@ -546,7 +503,7 @@ Parsing FAILED.
# Upon stack overflow, all symbols on the stack should be destroyed.
# Only check for yacc.c.
AT_YACC_IF([
AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2,
AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2, [],
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
@@ -581,7 +538,7 @@ sending: '(' (18@180-189)
sending: 'x' (19@190-199)
thing (19@190-199): 'x' (19@190-199)
sending: ')' (20@200-209)
200-209: memory exhausted
200.200-209.208: memory exhausted
Freeing nterm thing (19@190-199)
Freeing nterm line (15@150-179)
Freeing nterm line (12@120-149)
@@ -593,7 +550,8 @@ Parsing FAILED (status 2).
]])
])
])
AT_BISON_OPTION_POPDEFS
])# _AT_CHECK_PRINTER_AND_DESTRUCTOR
# AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
@@ -632,7 +590,7 @@ AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union])
# called for $end, and that $$ and @$ work correctly.
AT_SETUP([Default tagless %printer and %destructor])
AT_BISON_OPTION_PUSHDEFS([%locations])
AT_DATA_GRAMMAR([[input.y]],
[[%error-verbose
%debug
@@ -645,8 +603,8 @@ AT_DATA_GRAMMAR([[input.y]],
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
]AT_YYLEX_DECLARE[
]AT_YYERROR_DECLARE[
# define USE(SYM)
%}
@@ -677,25 +635,8 @@ AT_DATA_GRAMMAR([[input.y]],
start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
%%
static int
yylex (void)
{
static char const input[] = "abcd";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
yylval = input[toknum++];
yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum;
return yylval;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["abcd"], [[yylval = res]])[
int
main (void)
@@ -728,7 +669,7 @@ Reading a token: Next token is token 'd' (1.4-1.4: <> printer for 'd' @ 4)
Shifting token 'd' (1.4-1.4: <> printer for 'd' @ 4)
Entering state 6
Reading a token: Now at end of input.
syntax error, unexpected $end, expecting 'e'
1.5-4: syntax error, unexpected $end, expecting 'e'
Error: popping token 'd' (1.4-1.4: <> printer for 'd' @ 4)
Stack now 0 1 3 5
Error: popping token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3)
@@ -741,6 +682,7 @@ Cleanup: discarding lookahead token $end (1.5-1.5: )
Stack now 0
]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -750,7 +692,7 @@ AT_CLEANUP
## ------------------------------------------------------ ##
AT_SETUP([Default tagged and per-type %printer and %destructor])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%error-verbose
%debug
@@ -758,8 +700,8 @@ AT_DATA_GRAMMAR([[input.y]],
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
# define USE(SYM)
%}
@@ -805,22 +747,8 @@ start:
;
%%
static int
yylex (void)
{
static char const input[] = "abcdef";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
return input[toknum++];
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["abcdef"])[
int
main (void)
@@ -878,6 +806,7 @@ Cleanup: discarding lookahead token $end ()
Stack now 0
]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -895,6 +824,7 @@ m4_define([_AT_CHECK_DEFAULT_PRINTER_AND_DESTRUCTOR_FOR_END_TOKEN],
[m4_pushdef([kind], []) m4_pushdef([not_kind], [*])],
[m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])])
AT_BISON_OPTION_PUSHDEFS([%locations])
AT_DATA_GRAMMAR([[input]]$1[[.y]],
[[%error-verbose
%debug
@@ -907,8 +837,8 @@ AT_DATA_GRAMMAR([[input]]$1[[.y]],
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
# define USE(SYM)
%}
@@ -950,12 +880,7 @@ yylex (void)
yylloc.first_column = yylloc.last_column = 1;
return 0;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
int
main (void)
@@ -964,6 +889,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input$1.c input$1.y])
AT_COMPILE([input$1])
@@ -1010,15 +936,15 @@ AT_SETUP([Default %printer and %destructor are not for error or $undefined])
# semantic value, which would be initialized from the lookahead, which
# would be destroyed separately.
# - For $undefined, who knows what the semantic value would be.
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%debug
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
# define USE(SYM)
%}
@@ -1039,24 +965,8 @@ start:
;
%%
static int
yylex (void)
{
static char const input[] = "abd";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
yylval = input[toknum++];
return yylval;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["abd"], [yylval = res])[
int
main (void)
{
@@ -1064,6 +974,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input])
@@ -1125,14 +1036,15 @@ AT_SETUP([Default %printer and %destructor are not for $accept])
# true for $undefined and the error token, so there are three warnings for
# %printer and three for %destructor.)
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%debug /* So that %printer is actually compiled. */
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
# define USE(SYM)
%}
@@ -1153,28 +1065,15 @@ AT_DATA_GRAMMAR([[input.y]],
start: { USE($$); } ;
%%
static int
yylex (void)
{
static int called;
if (called++)
abort ();
return 0;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
int
main (void)
{
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input])
@@ -1189,14 +1088,15 @@ AT_CLEANUP
AT_SETUP([Default %printer and %destructor for mid-rule values])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%debug /* So that %printer is actually compiled. */
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
# define USE(SYM)
# define YYLTYPE int
# define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs)
@@ -1220,22 +1120,8 @@ start:
;
%%
static int
yylex (void)
{
static int called;
if (called++)
abort ();
return 0;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
int
main (void)
{
@@ -1243,6 +1129,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y], 0,,
[[input.y:33.3-23: warning: unset value: $$
@@ -1296,21 +1183,21 @@ AT_CLEANUP
# Bison once forgot to check for @$ in actions other than semantic actions.
# AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE)
# -------------------------------------------------------
# -------------------------------------------
m4_define([AT_CHECK_ACTION_LOCATIONS],
[AT_SETUP([[@$ in ]$1[ implies %locations]])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%code {
#include <stdio.h>
static int yylex (void);
static void yyerror (char const *msg);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
%debug
]$1[ {
printf ("%d\n", @$.first_line);
fprintf (stderr, "%d\n", @$.first_line);
} ]m4_if($1, [%initial-action], [], [[start]])[
%%
@@ -1325,12 +1212,7 @@ yylex (void)
return 0;
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -1340,7 +1222,7 @@ main (void)
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP])
AT_CHECK_ACTION_LOCATIONS([[%initial-action]])
@@ -1357,7 +1239,7 @@ AT_SETUP([[Fix user actions without a trailing semicolon]])
# This feature is undocumented, but we accidentally broke it in 2.3a,
# and there was a complaint at:
# <http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00001.html>.
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y],
[[%%
start: test2 test1 test0 testc;
@@ -1407,6 +1289,7 @@ no_semi
[]"broken\" $ @ $$ @$ [];\
string;"}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]], [0], [],
[[input.y:8.48: warning: a ';' might be needed at the end of action code
@@ -1462,13 +1345,14 @@ AT_CLEANUP
AT_SETUP([[Destroying lookahead assigned by semantic action]])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[
%code {
#include <assert.h>
#include <stdio.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
#define USE(Var)
}
@@ -1496,27 +1380,15 @@ accept: /*empty*/ {
} ;
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
static char const *input = "a";
return *input++;
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["a"])[
int
main (void)
{
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
AT_PARSER_CHECK([[./input]], [[0]], [],
@@ -1532,6 +1404,8 @@ AT_CLEANUP
AT_SETUP([[YYBACKUP]])
AT_BISON_OPTION_PUSHDEFS([%pure-parser])
AT_DATA_GRAMMAR([input.y],
[[
%error-verbose
@@ -1542,8 +1416,8 @@ AT_DATA_GRAMMAR([input.y],
# include <stdlib.h>
# include <assert.h>
static void yyerror (const char *msg);
static int yylex (YYSTYPE *yylval);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
%%
input:
@@ -1557,21 +1431,8 @@ exp:
;
%%
static int
yylex (YYSTYPE *yylval)
{
static char const input[] = "bcd";
static size_t toknum;
assert (toknum < sizeof input);
*yylval = (toknum + 1) * 10;
return input[toknum++];
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[
int
main (void)
@@ -1580,6 +1441,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
+8 -3
View File
@@ -29,9 +29,11 @@ CPPFLAGS="-I$abs_top_builddir/lib @CPPFLAGS@"
# Is the compiler GCC?
GCC='@GCC@'
# We want no optimization.
O0CFLAGS=`echo '@CFLAGS@' | sed 's/-O[0-9] *//'`
O0CXXFLAGS=`echo '@CXXFLAGS@' | sed 's/-O[0-9] *//'`
# We want no optimization, as they uncover warnings (therefore,
# failures) about uninitialized variables in the test suite. FIXME:
# fix the warnings, not the flags.
O0CFLAGS=`echo '@CFLAGS@' | sed 's/-O[0-9s] *//g'`
O0CXXFLAGS=`echo '@CXXFLAGS@' | sed 's/-O[0-9s] *//g'`
# Sometimes a test group needs to ignore gcc warnings, so it locally
# sets CFLAGS to this.
@@ -47,10 +49,13 @@ BISON_CXX_WORKS='@BISON_CXX_WORKS@'
# Handle --compile-c-with-cxx here, once CXX and CXXFLAGS are known.
if "$at_arg_compile_c_with_cxx"; then
CC_IS_CXX=1
CC=$CXX
O0CFLAGS=$O0CXXFLAGS
NO_WERROR_CFLAGS=$NO_WERROR_CXXFLAGS
CFLAGS=$CXXFLAGS
else
CC_IS_CXX=0
fi
+135 -120
View File
@@ -33,21 +33,90 @@
# Don't call this macro directly, because it contains some occurrences
# of `$1' etc. which will be interpreted by m4. So you should call it
# with $1, $2, and $3 as arguments, which is what AT_DATA_CALC_Y does.
#
# When %defines is not passed, generate a single self-contained file.
# Otherwise, generate three: calc.y with the parser, calc-lex.c with
# the scanner, and calc-main.c with "main()". This is in order to
# stress the use of the generated parser header. To avoid code
# duplication, AT_CALC_LEX and AT_CALC_MAIN contain the body of these
# two later files.
m4_define([_AT_DATA_CALC_Y],
[m4_if([$1$2$3], $[1]$[2]$[3], [],
[m4_fatal([$0: Invalid arguments: $@])])dnl
m4_pushdef([AT_CALC_MAIN],
[#include <assert.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#else
# undef alarm
# define alarm(seconds) /* empty */
#endif
AT_SKEL_CC_IF([[
/* A C++ ]AT_NAME_PREFIX[parse that simulates the C signature. */
int
]AT_NAME_PREFIX[parse (]AT_PARAM_IF([semantic_value *result, int *count]))[
{
]AT_NAME_PREFIX[::parser parser]AT_PARAM_IF([ (result, count)])[;
#if ]AT_API_PREFIX[DEBUG
parser.set_debug_level (1);
#endif
return parser.parse ();
}
]])[
semantic_value global_result = 0;
int global_count = 0;
/* A C main function. */
int
main (int argc, const char **argv)
{
semantic_value result = 0;
int count = 0;
int status;
/* This used to be alarm (10), but that isn't enough time for
a July 1995 vintage DEC Alphastation 200 4/100 system,
according to Nelson H. F. Beebe. 100 seconds is enough. */
alarm (100);
if (argc == 2)
input = fopen (argv[1], "r");
else
input = stdin;
if (!input)
{
perror (argv[1]);
return 3;
}
]AT_SKEL_CC_IF([], [m4_bmatch([$4], [%debug],
[ ]AT_NAME_PREFIX[debug = 1;])])[
status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count]])[);
if (fclose (input))
perror ("fclose");
assert (global_result == result);
assert (global_count == count);
return status;
}
]])
m4_pushdef([AT_CALC_LEX],
[[#include <ctype.h>
int ]AT_NAME_PREFIX[lex (]AT_LEX_FORMALS[);
static int get_char (]AT_LEX_FORMALS[);
static void unget_char (]AT_LEX_PRE_FORMALS[ int c);
]AT_YYLEX_DECLARE_EXTERN[
static int get_char (]AT_YYLEX_FORMALS[);
static void unget_char (]AT_YYLEX_PRE_FORMALS[ int c);
]AT_LOCATION_IF([
static YYLTYPE last_yylloc;
static AT_YYLTYPE last_yylloc;
])[
static int
get_char (]AT_LEX_FORMALS[)
get_char (]AT_YYLEX_FORMALS[)
{
int res = getc (input);
]AT_USE_LEX_ARGS[;
@@ -65,7 +134,7 @@ get_char (]AT_LEX_FORMALS[)
}
static void
unget_char (]AT_LEX_PRE_FORMALS[ int c)
unget_char (]AT_YYLEX_PRE_FORMALS[ int c)
{
]AT_USE_LEX_ARGS[;
]AT_LOCATION_IF([
@@ -76,26 +145,26 @@ unget_char (]AT_LEX_PRE_FORMALS[ int c)
}
static int
read_signed_integer (]AT_LEX_FORMALS[)
read_signed_integer (]AT_YYLEX_FORMALS[)
{
int c = get_char (]AT_LEX_ARGS[);
int c = get_char (]AT_YYLEX_ARGS[);
int sign = 1;
int n = 0;
]AT_USE_LEX_ARGS[;
if (c == '-')
{
c = get_char (]AT_LEX_ARGS[);
c = get_char (]AT_YYLEX_ARGS[);
sign = -1;
}
while (isdigit (c))
{
n = 10 * n + (c - '0');
c = get_char (]AT_LEX_ARGS[);
c = get_char (]AT_YYLEX_ARGS[);
}
unget_char (]AT_LEX_PRE_ARGS[ c);
unget_char (]AT_YYLEX_PRE_ARGS[ c);
return sign * n;
}
@@ -107,8 +176,7 @@ read_signed_integer (]AT_LEX_FORMALS[)
| blanks and tabs, returns 0 for EOF. |
`---------------------------------------------------------------*/
int
]AT_NAME_PREFIX[lex (]AT_LEX_FORMALS[)
]AT_YYLEX_PROTOTYPE[
{
static int init = 1;
int c;
@@ -130,13 +198,13 @@ int
AT_LOC_FIRST_LINE = AT_LOC_LAST_LINE;
])[
}
while ((c = get_char (]AT_LEX_ARGS[)) == ' ' || c == '\t');
while ((c = get_char (]AT_YYLEX_ARGS[)) == ' ' || c == '\t');
/* process numbers */
if (c == '.' || isdigit (c))
{
unget_char (]AT_LEX_PRE_ARGS[ c);
]AT_VAL[.ival = read_signed_integer (]AT_LEX_ARGS[);
unget_char (]AT_YYLEX_PRE_ARGS[ c);
]AT_VAL[.ival = read_signed_integer (]AT_YYLEX_ARGS[);
return NUM;
}
@@ -196,42 +264,28 @@ AT_SKEL_CC_IF(
%code provides
{
#include <stdio.h>
/* The input. */
extern FILE *input;]AT_SKEL_CC_IF([[
#ifndef YYLTYPE
# define YYLTYPE ]AT_NAME_PREFIX[::parser::location_type
#endif
]])[
#include <stdio.h>
/* The input. */
extern FILE *input;
extern semantic_value global_result;
extern int global_count;
}
%code
{
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#else
# undef alarm
# define alarm(seconds) /* empty */
#endif
#define USE(Var)
FILE *input;
static semantic_value global_result = 0;
static int global_count = 0;
static int power (int base, int exponent);
]AT_SKEL_CC_IF(,
[/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
static void yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])
[static void yyerror (AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])
AT_PARAM_IF([semantic_value *result, int *count, ])
const char *s
);])[
int yylex (]AT_LEX_FORMALS[);
]AT_YYLEX_DECLARE_EXTERN[
}
]AT_SKEL_CC_IF([AT_LOCATION_TYPE_IF([], [
@@ -250,7 +304,7 @@ int yylex (]AT_LEX_FORMALS[);
%token <ival> NUM "number"
%type <ival> exp
%nonassoc '=' /* comparison */
%nonassoc '=' /* comparison */
%left '-' '+'
%left '*' '/'
%left NEG /* negation--unary minus */
@@ -289,6 +343,16 @@ exp:
;
%%
static int
power (int base, int exponent)
{
int res = 1;
assert (0 <= exponent);
for (/* Niente */; exponent; --exponent)
res *= base;
return res;
}
]AT_SKEL_CC_IF(
[AT_LOCATION_TYPE_IF([[
std::ostream&
@@ -302,29 +366,10 @@ exp:
return o;
}
]])
/* A C++ error reporting function. */
void
AT_NAME_PREFIX::parser::error (const location_type& l, const std::string& m)
{
(void) l;
std::cerr << AT_LOCATION_IF([l << ": " << ])m << std::endl;
}
/* A C++ yyparse that simulates the C signature. */
int
yyparse (AT_PARAM_IF([semantic_value *result, int *count]))
{
AT_NAME_PREFIX::parser parser[]AT_PARAM_IF([ (result, count)]);
#if YYDEBUG
parser.set_debug_level (1);
#endif
return parser.parse ();
}
],
AT_YYERROR_DEFINE],
[/* A C error reporting function. */
static void
yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])
yyerror (AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])
AT_PARAM_IF([semantic_value *result, int *count, ])
const char *s)
{
@@ -334,67 +379,29 @@ AT_YYERROR_SEES_LOC_IF([
AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN);
if (AT_LOC_FIRST_LINE != AT_LOC_LAST_LINE)
fprintf (stderr, "-%d.%d",
AT_LOC_LAST_LINE, AT_LOC_LAST_COLUMN - 1);
AT_LOC_LAST_LINE, AT_LOC_LAST_COLUMN - 1);
else if (AT_LOC_FIRST_COLUMN != AT_LOC_LAST_COLUMN - 1)
fprintf (stderr, "-%d",
AT_LOC_LAST_COLUMN - 1);
AT_LOC_LAST_COLUMN - 1);
fprintf (stderr, ": ");])
fprintf (stderr, "%s\n", s);
}])[
]AT_DEFINES_IF(, [AT_CALC_LEX])[
static int
power (int base, int exponent)
{
int res = 1;
assert (0 <= exponent);
for (/* Niente */; exponent; --exponent)
res *= base;
return res;
}
/* A C main function. */
int
main (int argc, const char **argv)
{
semantic_value result = 0;
int count = 0;
int status;
/* This used to be alarm (10), but that isn't enough time for
a July 1995 vintage DEC Alphastation 200 4/100 system,
according to Nelson H. F. Beebe. 100 seconds is enough. */
alarm (100);
if (argc == 2)
input = fopen (argv[1], "r");
else
input = stdin;
if (!input)
{
perror (argv[1]);
return 3;
}
]AT_SKEL_CC_IF([], [m4_bmatch([$4], [%debug],
[ yydebug = 1;])])[
status = yyparse (]AT_PARAM_IF([[&result, &count]])[);
if (fclose (input))
perror ("fclose");
if (global_result != result)
abort ();
if (global_count != count)
abort ();
return status;
}
]AT_DEFINES_IF([],
[AT_CALC_LEX
AT_CALC_MAIN])[
]])
AT_DEFINES_IF([AT_DATA_SOURCE([[calc-lex.c]AT_SKEL_CC_IF([[c]])],
[[#include "calc.h]AT_SKEL_CC_IF([[h]])["
]AT_CALC_LEX])])
]AT_CALC_LEX])
AT_DATA_SOURCE([[calc-main.c]AT_SKEL_CC_IF([[c]])],
[[#include "calc.h]AT_SKEL_CC_IF([[h]])["
]AT_CALC_MAIN])
])
m4_popdef([AT_CALC_MAIN])
m4_popdef([AT_CALC_LEX])
])# _AT_DATA_CALC_Y
@@ -493,21 +500,20 @@ AT_CHECK([cat stderr], 0, [expout])
])
# AT_CHECK_CALC([BISON-OPTIONS, [EXPECTED-TO-FAIL]])
# --------------------------------------------------
# AT_CHECK_CALC([BISON-OPTIONS])
# ------------------------------
# Start a testing chunk which compiles `calc' grammar with
# BISON-OPTIONS, and performs several tests over the parser.
# However, if EXPECTED-TO-FAIL is nonempty, this test is expected to fail.
m4_define([AT_CHECK_CALC],
[# We use integers to avoid dependencies upon the precision of doubles.
AT_SETUP([Calculator $1])
[m4_ifval([$2], [m4_fatal([$0: expected a single argument])])
m4_ifval([$2], [AT_CHECK([exit 77])])
# We use integers to avoid dependencies upon the precision of doubles.
AT_SETUP([Calculator $1])
AT_BISON_OPTION_PUSHDEFS([$1])
AT_DATA_CALC_Y([$1])
AT_FULL_COMPILE([calc], [AT_DEFINES_IF([[lex]])])
AT_FULL_COMPILE([calc], AT_DEFINES_IF([[lex], [main]]))
# Test the priorities.
_AT_CHECK_CALC([$1],
@@ -622,14 +628,16 @@ AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure %locations])
AT_CHECK_CALC_LALR([%error-verbose %locations])
AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%error-verbose %locations %defines %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%debug])
AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure %error-verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
# ----------------------- #
@@ -651,6 +659,7 @@ AT_CHECK_CALC_GLR()
AT_CHECK_CALC_GLR([%defines])
AT_CHECK_CALC_GLR([%locations])
AT_CHECK_CALC_GLR([%name-prefix "calc"])
AT_CHECK_CALC_GLR([%define api.prefix "calc"])
AT_CHECK_CALC_GLR([%verbose])
AT_CHECK_CALC_GLR([%yacc])
AT_CHECK_CALC_GLR([%error-verbose])
@@ -662,10 +671,12 @@ AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix "calc" %verbo
AT_CHECK_CALC_GLR([%debug])
AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
# ----------------------------- #
@@ -687,11 +698,13 @@ m4_define([AT_CHECK_CALC_LALR1_CC],
AT_CHECK_CALC_LALR1_CC([])
AT_CHECK_CALC_LALR1_CC([%define location_type Span])
AT_CHECK_CALC_LALR1_CC([%error-verbose %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%error-verbose %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%error-verbose %debug %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
@@ -714,6 +727,7 @@ m4_define([AT_CHECK_CALC_GLR_CC],
AT_CHECK_CALC_GLR_CC([])
AT_CHECK_CALC_GLR_CC([%define location_type Span])
AT_CHECK_CALC_GLR_CC([%error-verbose %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR_CC([%error-verbose %define api.prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR_CC([%debug])
AT_CHECK_CALC_GLR_CC([%error-verbose %debug %name-prefix "calc" %verbose %yacc])
@@ -721,3 +735,4 @@ AT_CHECK_CALC_GLR_CC([%error-verbose %debug %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc])
AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %define api.prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
+15 -48
View File
@@ -50,20 +50,17 @@ AT_CLEANUP
AT_SETUP([%nonassoc and eof])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define YYERROR_VERBOSE 1
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
/* The current argument. */
static const char *input;
@@ -71,8 +68,7 @@ static int
yylex (void)
{
static size_t toknum;
if (! (toknum <= strlen (input)))
abort ();
assert (toknum <= strlen (input));
return input[toknum++];
}
@@ -93,6 +89,7 @@ main (int argc, const char *argv[])
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
m4_pushdef([AT_NONASSOC_AND_EOF_CHECK],
[AT_BISON_CHECK([$1[ -o input.c input.y]])
@@ -171,7 +168,7 @@ AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
#include <string>]], [[
#include <assert.h>
#include <stdio.h>
void yyerror (char const *msg);]])[
]AT_YYERROR_DECLARE])[
]AT_YYLEX_PROTOTYPE[;
#define USE(Var)
}
@@ -212,31 +209,11 @@ public Object getLVal ()
*lvalp = 1;
return *input++;
}]])[
/*----------.
| yyerror. |
`----------*/]AT_SKEL_JAVA_IF([[
public void yyerror (String msg)
{
System.err.println (msg);
}
]AT_YYERROR_DEFINE[
]AT_SKEL_JAVA_IF([[
};
%%]], [AT_SKEL_CC_IF([[
void
yy::parser::error (const yy::location &, std::string const &msg)
{
std::cerr << msg << std::endl;
}]], [[
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}]])])[
%%]])[
/*-------.
| main. |
@@ -471,12 +448,12 @@ AT_CLEANUP
# with minimal LR parser tables.
AT_SETUP([[LAC: %nonassoc requires splitting canonical LR states]])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%code {
#include <stdio.h>
void yyerror (char const *);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
%error-verbose
@@ -513,19 +490,8 @@ look:
reduce-nonassoc: %prec 'a';
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
int
yylex (void)
{
char const *input = "aaa";
return *input++;
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["aaa"])[
int
main (void)
@@ -533,6 +499,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
# Show canonical LR's failure.
AT_BISON_CHECK([[-Dlr.type=canonical-lr -o input.c input.y]],
+51 -70
View File
@@ -23,15 +23,15 @@ AT_BANNER([[C++ Type Syntax (GLR).]])
# and with RESOLVE1 and RESOLVE2 as annotations on the conflicted rule for
# stmt. Then compile the result.
m4_define([_AT_TEST_GLR_CXXTYPES],
[
AT_BISON_OPTION_PUSHDEFS([$1])
[AT_BISON_OPTION_PUSHDEFS([%glr-parser $1])
AT_DATA_GRAMMAR([types.y],
[[/* Simplified C++ Type and Expression Grammar. */
$1
%{
%code requires
{
#include <stdio.h>
union Node {
struct {
@@ -51,33 +51,22 @@ $1
} term;
};
typedef union Node Node;
#define YYSTYPE Node *
}
%code
{
static Node *new_nterm (char const *, Node *, Node *, Node *);
static Node *new_term (char *);
static void free_node (Node *);
static char *node_to_string (Node *);
#define YYSTYPE Node *
]m4_bmatch([$2], [stmtMerge],
[ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[
#define YYINITDEPTH 10
#define YYSTACKEXPANDABLE 1
struct YYLTYPE;
#if YYPURE
# if YYLSP_NEEDED
# define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
# define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
# else
# define LEX_PARAMETERS YYSTYPE *lvalp
# endif
#endif
#ifndef LEX_PARAMETERS
# define LEX_PARAMETERS void
#endif
#ifndef ERROR_PARAMETERS
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
void yyerror (ERROR_PARAMETERS);
%}
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
%token TYPENAME ID
@@ -133,19 +122,20 @@ declarator : ID
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
int
main (int argc, char **argv)
{
if (argc != 2)
abort ();
assert (argc == 2);
if (!freopen (argv[1], "r", stdin))
return 3;
return yyparse ();
}
int
yylex (LEX_PARAMETERS)
]AT_YYERROR_DEFINE[
]AT_YYLEX_PROTOTYPE[
{
char buffer[256];
int c;
@@ -162,8 +152,7 @@ yylex (LEX_PARAMETERS)
while (1)
{
if (feof (stdin))
abort ();
assert (!feof (stdin));
c = getchar ();
switch (c)
{
@@ -181,11 +170,9 @@ yylex (LEX_PARAMETERS)
break;
default:
{
int tok;
#if YYLSP_NEEDED
int tok;]AT_LOCATION_IF([[
yylloc.first_line = yylloc.last_line = lineNum;
yylloc.first_column = colNum;
#endif
yylloc.first_column = colNum;]])[
if (isalpha (c))
{
i = 0;
@@ -194,8 +181,7 @@ yylex (LEX_PARAMETERS)
{
buffer[i++] = c;
colNum += 1;
if (i == sizeof buffer - 1)
abort ();
assert (i != sizeof buffer - 1);
c = getchar ();
}
while (isalnum (c) || c == '_');
@@ -210,27 +196,14 @@ yylex (LEX_PARAMETERS)
colNum += 1;
tok = c;
yylval = YY_NULL;
}
#if YYLSP_NEEDED
yylloc.last_column = colNum-1;
#endif
}]AT_LOCATION_IF([[
yylloc.last_column = colNum-1;]])[
return tok;
}
}
}
}
void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
/* Pacify GCC by using llocp. */
if (! llocp)
abort ();
#endif
fprintf (stderr, "%s\n", s);
}
static Node *
new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
{
@@ -351,7 +324,7 @@ AT_BISON_OPTION_POPDEFS
])
m4_define([_AT_RESOLVED_GLR_OUTPUT],
[[[+(z,q)
[[+(z,q)
<declare>(T,x)
<init-declare>(T,x,y)
=(x,y)
@@ -360,10 +333,10 @@ m4_define([_AT_RESOLVED_GLR_OUTPUT],
<init-declare>(T,y,+(z,q))
<error>
+(z,q)
]]])
]])
m4_define([_AT_RESOLVED_GLR_OUTPUT_WITH_LOC],
[[[3.0-3.5: +(z,q)
[[3.0-3.5: +(z,q)
5.0-5.3: <declare>(T,x)
7.0-7.7: <init-declare>(T,x,y)
9.0-9.5: =(x,y)
@@ -372,10 +345,10 @@ m4_define([_AT_RESOLVED_GLR_OUTPUT_WITH_LOC],
15.0-15.13: <init-declare>(T,y,+(z,q))
17.0-17.15: <error>
19.0-19.5: +(z,q)
]]])
]])
m4_define([_AT_AMBIG_GLR_OUTPUT],
[[[+(z,q)
[[+(z,q)
<declare>(T,x)
<init-declare>(T,x,y)
=(x,y)
@@ -384,10 +357,10 @@ m4_define([_AT_AMBIG_GLR_OUTPUT],
<OR>(<init-declare>(T,y,+(z,q)),=(<cast>(y,T),+(z,q)))
<error>
+(z,q)
]]])
]])
m4_define([_AT_AMBIG_GLR_OUTPUT_WITH_LOC],
[[[3.0-3.5: +(z,q)
[[3.0-3.5: +(z,q)
5.0-5.3: <declare>(T,x)
7.0-7.7: <init-declare>(T,x,y)
9.0-9.5: =(x,y)
@@ -396,15 +369,23 @@ m4_define([_AT_AMBIG_GLR_OUTPUT_WITH_LOC],
15.0-15.13: <OR>(<init-declare>(T,y,+(z,q)),=(<cast>(y,T),+(z,q)))
17.0-17.15: <error>
19.0-19.5: +(z,q)
]]])
]])
m4_define([_AT_GLR_STDERR],
[[[syntax error
]]])
[[syntax error
]])
m4_define([_AT_GLR_STDERR_WITH_LOC],
[[17.5-4: syntax error
]])
m4_define([_AT_VERBOSE_GLR_STDERR],
[[[syntax error, unexpected ID, expecting '=' or '+' or ')'
]]])
[[syntax error, unexpected ID, expecting '=' or '+' or ')'
]])
m4_define([_AT_VERBOSE_GLR_STDERR_WITH_LOC],
[[17.5-4: syntax error, unexpected ID, expecting '=' or '+' or ')'
]])
## ---------------------------------------------------- ##
## Compile the grammar described in the documentation. ##
@@ -414,59 +395,59 @@ AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
_AT_TEST_GLR_CXXTYPES([],
[%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_WITH_LOC])
AT_CLEANUP
AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
_AT_TEST_GLR_CXXTYPES([%define api.pure],
[%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])
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_WITH_LOC])
AT_CLEANUP
AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
_AT_TEST_GLR_CXXTYPES([],
[%merge <stmtMerge>], [%merge <stmtMerge>])
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 <stmtMerge>], [%merge <stmtMerge>])
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_WITH_LOC])
AT_CLEANUP
AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
_AT_TEST_GLR_CXXTYPES([%define api.pure],
[%merge <stmtMerge>], [%merge <stmtMerge>])
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 <stmtMerge>],[%merge <stmtMerge>])
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_WITH_LOC])
AT_CLEANUP
AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
_AT_TEST_GLR_CXXTYPES([%error-verbose],
[%merge <stmtMerge>], [%merge <stmtMerge>])
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
+138 -282
View File
@@ -24,6 +24,7 @@ AT_BANNER([[GLR Regression Tests]])
AT_SETUP([Badly Collapsed GLR States])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr1.y],
[[/* Regression Test: Improper state compression */
/* Reported by Scott McPeak */
@@ -31,11 +32,12 @@ AT_DATA_GRAMMAR([glr-regr1.y],
%{
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define YYSTYPE int
static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
int yylex (void);
void yyerror (char const *msg);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
@@ -71,12 +73,7 @@ main (void)
return yyparse ();
}
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
int
yylex (void)
@@ -84,8 +81,7 @@ yylex (void)
for (;;)
{
int ch;
if (feof (stdin))
abort ();
assert (!feof (stdin));
ch = getchar ();
if (ch == EOF)
return 0;
@@ -94,6 +90,7 @@ yylex (void)
}
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr1.c glr-regr1.y]], 0, [],
[glr-regr1.y: conflicts: 1 shift/reduce
@@ -119,6 +116,7 @@ AT_CLEANUP
AT_SETUP([Improper handling of embedded actions and dollar(-N) in GLR parsers])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr2a.y],
[[/* Regression Test: Improper handling of embedded actions and $-N */
/* Reported by S. Eken */
@@ -130,8 +128,9 @@ AT_DATA_GRAMMAR([glr-regr2a.y],
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int yylex (void);
void yyerror (char const *);
#include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%glr-parser
@@ -171,7 +170,7 @@ var_printer: 'v'
{ printf ("Variable: '%s'\n", $-1); }
%%
]AT_YYERROR_DEFINE[
FILE *input;
int
@@ -179,9 +178,9 @@ yylex (void)
{
char buf[50];
char *s;
if (feof (stdin))
abort ();
switch (fscanf (input, " %1[a-z,]", buf)) {
assert (!feof (stdin));
switch (fscanf (input, " %1[a-z,]", buf))
{
case 1:
return buf[0];
case EOF:
@@ -191,19 +190,13 @@ yylex (void)
}
if (fscanf (input, "%49s", buf) != 1)
return 0;
if (sizeof buf - 1 <= strlen (buf))
abort ();
assert (strlen (buf) < sizeof buf - 1);
s = (char *) malloc (strlen (buf) + 1);
strcpy (s, buf);
yylval = s;
return 'V';
}
void
yyerror (char const *s)
{ printf ("%s\n", s);
}
int
main (int argc, char **argv)
{
@@ -212,6 +205,7 @@ main (int argc, char **argv)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr2a.c glr-regr2a.y]], 0, [],
[glr-regr2a.y: conflicts: 2 shift/reduce
@@ -238,6 +232,7 @@ AT_CLEANUP
AT_SETUP([Improper merging of GLR delayed action sets])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr3.y],
[[/* Regression Test: Improper merging of GLR delayed action sets. */
/* Reported by M. Rosien */
@@ -246,10 +241,11 @@ AT_DATA_GRAMMAR([glr-regr3.y],
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
static int MergeRule (int x0, int x1);
static void yyerror (char const * s);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
#define RULE(x) (1 << (x))
@@ -290,13 +286,12 @@ NT6 : P1 NT1 O1 T3 P2 { $$ = RULE(11) | $2; } %merge<MergeRule>
%%
static int MergeRule (int x0, int x1) {
static int
MergeRule (int x0, int x1)
{
return x0 | x1;
}
static void yyerror(char const * s) {
fprintf(stderr,"error: %s\n",s);
}
]AT_YYERROR_DEFINE[
FILE *input = YY_NULL;
@@ -307,8 +302,7 @@ int T[] = { T1, T2, T3, T4 };
int yylex (void)
{
char inp[3];
if (feof (stdin))
abort ();
assert (!feof (stdin));
if (fscanf (input, "%2s", inp) == EOF)
return 0;
switch (inp[0])
@@ -320,12 +314,15 @@ int yylex (void)
return BAD_CHAR;
}
int main(int argc, char* argv[]) {
int
main(int argc, char* argv[])
{
input = stdin;
if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3;
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr3.c glr-regr3.y]], 0, [],
[glr-regr3.y: conflicts: 1 shift/reduce, 1 reduce/reduce
@@ -347,6 +344,7 @@ AT_CLEANUP
AT_SETUP([Duplicate representation of merged trees])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr4.y],
[[
%union { char *ptr; }
@@ -359,8 +357,8 @@ AT_DATA_GRAMMAR([glr-regr4.y],
#include <string.h>
static char *merge (YYSTYPE, YYSTYPE);
static char *make_value (char const *, char const *);
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static char *ptrs[100];
static char **ptrs_next = ptrs;
%}
@@ -384,16 +382,8 @@ A2: 'a' { $$ = make_value ("A2", "'a'"); } ;
B: 'a' { $$ = make_value ("B", "'a'"); } ;
%%
static int
yylex (void)
{
static char const input[] = "a";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
return input[toknum++];
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["a"])[
int
main (void)
@@ -423,13 +413,8 @@ merge (YYSTYPE s1, YYSTYPE s2)
sprintf (value, format, s1.ptr, s2.ptr);
return value;
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr4.c glr-regr4.y]], 0, [],
[glr-regr4.y: conflicts: 1 reduce/reduce
@@ -450,13 +435,14 @@ AT_CLEANUP
AT_SETUP([User destructor for unresolved GLR semantic value])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr5.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
enum { MAGIC_VALUE = -1057808125 }; /* originally chosen at random */
%}
@@ -480,29 +466,15 @@ start:
;
%%
static int
yylex (void)
{
static char const input[] = "a";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
return input[toknum++];
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYLEX_DEFINE(["a"])[
]AT_YYERROR_DEFINE[
int
main (void)
{
return yyparse () != 1;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr5.c glr-regr5.y]], 0, [],
[glr-regr5.y: conflicts: 1 reduce/reduce
@@ -523,13 +495,14 @@ AT_CLEANUP
AT_SETUP([User destructor after an error during a split parse])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr6.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%glr-parser
@@ -545,29 +518,15 @@ AT_DATA_GRAMMAR([glr-regr6.y],
start: 'a' | 'a' ;
%%
static int
yylex (void)
{
static char const input[] = "a";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
return input[toknum++];
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["a"])[
int
main (void)
{
return yyparse () != 1;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr6.c glr-regr6.y]], 0, [],
[glr-regr6.y: conflicts: 1 reduce/reduce
@@ -590,13 +549,14 @@ AT_CLEANUP
AT_SETUP([Duplicated user destructor for lookahead])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr7.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
#define YYSTACKEXPANDABLE 0
typedef struct count_node {
int count;
@@ -641,12 +601,7 @@ yylex (void)
return 'a';
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -660,6 +615,7 @@ main (void)
return status;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr7.c glr-regr7.y]], 0, [],
[glr-regr7.y: conflicts: 2 reduce/reduce
@@ -682,14 +638,14 @@ AT_CLEANUP
AT_SETUP([Incorrectly initialized location for empty right-hand side in GLR])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr8.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
static void yyerror (char const *msg);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%token T_CONSTANT
@@ -723,12 +679,7 @@ OptSignalWord : /* empty */
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
static int lexIndex;
int yylex (void)
@@ -758,6 +709,7 @@ main (void)
return 0;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr8.c glr-regr8.y]], 0, [],
[glr-regr8.y: conflicts: 1 reduce/reduce
@@ -780,13 +732,14 @@ AT_CLEANUP
AT_SETUP([No users destructors if stack 0 deleted])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr9.y],
[[
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
# define YYSTACKEXPANDABLE 0
static int tokens = 0;
static int destructors = 0;
@@ -822,12 +775,7 @@ yylex (void)
return 'a';
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -841,6 +789,7 @@ main (void)
return !exit_status;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr9.c glr-regr9.y]], 0, [],
[glr-regr9.y: conflicts: 1 reduce/reduce
@@ -860,13 +809,14 @@ AT_CLEANUP
AT_SETUP([Corrupted semantic options if user action cuts parse])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr10.y],
[[
%{
# include <stdlib.h>
# include <stdio.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
#define GARBAGE_SIZE 50
static char garbage[GARBAGE_SIZE];
%}
@@ -883,21 +833,8 @@ start:
;
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
static int called;
if (called++)
abort ();
return 0;
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
int
main (void)
@@ -908,6 +845,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr10.c glr-regr10.y]], 0, [],
[glr-regr10.y: conflicts: 1 reduce/reduce
@@ -925,12 +863,13 @@ AT_CLEANUP
AT_SETUP([Undesirable destructors if user action cuts parse])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr11.y],
[[
%{
# include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static int destructors = 0;
# define USE(val)
%}
@@ -949,21 +888,8 @@ start:
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
static char const input[] = "a";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
return input[toknum++];
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["a"])[
int
main (void)
@@ -977,6 +903,7 @@ main (void)
return exit_status;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr11.c glr-regr11.y]], 0, [],
[glr-regr11.y: conflicts: 1 reduce/reduce
@@ -994,6 +921,7 @@ AT_CLEANUP
AT_SETUP([Leaked semantic values if user action cuts parse])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr12.y],
[[
%glr-parser
@@ -1006,9 +934,10 @@ AT_DATA_GRAMMAR([glr-regr12.y],
%{
# include <stdlib.h>
# include <assert.h>
static int merge (YYSTYPE, YYSTYPE);
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static int parent_rhs_before_value = 0;
static int merged_value = 0;
static int parent_rhs_after_value = 0;
@@ -1068,23 +997,10 @@ merge (YYSTYPE s1, YYSTYPE s2)
return dummy;
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
static int const input[] = { PARENT_RHS_AFTER, 0 };
static size_t toknum;
if (! (toknum < sizeof input / sizeof *input))
abort ();
if (input[toknum] == PARENT_RHS_AFTER)
parent_rhs_after_value = 1;
return input[toknum++];
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE([{ PARENT_RHS_AFTER, 0 }],
[if (res == PARENT_RHS_AFTER)
parent_rhs_after_value = 1;])[
int
main (void)
@@ -1108,6 +1024,7 @@ main (void)
return exit_status;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr12.c glr-regr12.y]], 0, [],
[glr-regr12.y: conflicts: 1 shift/reduce, 1 reduce/reduce
@@ -1127,6 +1044,7 @@ AT_CLEANUP
AT_SETUP([Incorrect lookahead during deterministic GLR])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr13.y],
[[
/* Tests:
@@ -1138,8 +1056,9 @@ AT_DATA_GRAMMAR([glr-regr13.y],
%{
#include <stdio.h>
static void yyerror (char const *);
static int yylex (void);
#include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static void print_lookahead (char const *);
#define USE(value)
%}
@@ -1190,24 +1109,9 @@ change_lookahead:
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
static char const input[] = "ab";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum + 1;
yylval.value = input[toknum] + 'A' - 'a';
return input[toknum++];
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["ab"],
[yylval.value = res + 'A' - 'a'])[
static void
print_lookahead (char const *reduction)
@@ -1237,6 +1141,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr13.c glr-regr13.y]], 0, [], [])
AT_COMPILE([glr-regr13])
@@ -1263,6 +1168,7 @@ AT_CLEANUP
AT_SETUP([Incorrect lookahead during nondeterministic GLR])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr14.y],
[[
/* Tests:
@@ -1289,8 +1195,9 @@ AT_DATA_GRAMMAR([glr-regr14.y],
%{
#include <stdlib.h>
#include <stdio.h>
static void yyerror (char const *);
static int yylex (void);
#include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static void print_lookahead (char const *);
static char merge (union YYSTYPE, union YYSTYPE);
#define USE(value)
@@ -1399,19 +1306,13 @@ no_look:
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
static int
yylex (void)
{
static char const input[] = "abcdddd";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
assert (toknum < sizeof input);
yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum + 1;
yylval.value = input[toknum] + 'A' - 'a';
@@ -1453,6 +1354,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr14.c glr-regr14.y]], 0, [],
[glr-regr14.y: conflicts: 3 reduce/reduce
@@ -1483,6 +1385,7 @@ AT_CLEANUP
AT_SETUP([Leaked semantic values when reporting ambiguity])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr15.y],
[[
%glr-parser
@@ -1490,8 +1393,8 @@ AT_DATA_GRAMMAR([glr-regr15.y],
%{
# include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static int parent_rhs_before_value = 0;
# define USE(val)
%}
@@ -1529,21 +1432,8 @@ ambiguity1: ;
ambiguity2: ;
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
static int called;
if (called++)
abort ();
return 0;
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
int
main (void)
@@ -1557,6 +1447,7 @@ main (void)
return exit_status;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr15.c glr-regr15.y]], 0, [],
[glr-regr15.y: conflicts: 2 reduce/reduce
@@ -1575,6 +1466,8 @@ AT_CLEANUP
## ------------------------------------------------------------------------- ##
AT_SETUP([Leaked lookahead after nondeterministic parse syntax error])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr16.y],
[[
%glr-parser
@@ -1582,8 +1475,9 @@ AT_DATA_GRAMMAR([glr-regr16.y],
%{
# include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
# include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static int lookahead_value = 0;
# define USE(val)
%}
@@ -1596,23 +1490,10 @@ alt2: ;
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
static char const input[] = "ab";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
if (input[toknum] == 'b')
lookahead_value = 1;
return input[toknum++];
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["ab"],
[if (res == 'b')
lookahead_value = 1])[
int
main (void)
@@ -1626,6 +1507,7 @@ main (void)
return exit_status;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr16.c glr-regr16.y]], 0, [],
[glr-regr16.y: conflicts: 1 reduce/reduce
@@ -1644,6 +1526,9 @@ AT_CLEANUP
## ------------------------------------------------------------------------- ##
AT_SETUP([Uninitialized location when reporting ambiguity])
AT_BISON_OPTION_PUSHDEFS([%glr-parser %locations %define api.pure])
AT_DATA_GRAMMAR([glr-regr17.y],
[[
%glr-parser
@@ -1654,8 +1539,8 @@ AT_DATA_GRAMMAR([glr-regr17.y],
%union { int dummy; }
%{
static void yyerror (YYLTYPE *, char const *);
static int yylex (YYSTYPE *, YYLTYPE *);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%initial-action {
@@ -1685,21 +1570,15 @@ empty1: ;
empty2: ;
%%
# include <assert.h>
static void
yyerror (YYLTYPE *locp, char const *msg)
{
fprintf (stderr, "%d.%d-%d.%d: %s.\n", locp->first_line,
locp->first_column, locp->last_line, locp->last_column, msg);
}
]AT_YYERROR_DEFINE[
static int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
{
static char const input[] = "ab";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
assert (toknum < sizeof input);
lvalp->dummy = 0;
llocp->first_line = llocp->last_line = 2;
llocp->first_column = toknum + 1;
@@ -1713,6 +1592,7 @@ main (void)
return yyparse () != 1;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr17.c glr-regr17.y]], 0, [],
[glr-regr17.y: conflicts: 3 reduce/reduce
@@ -1720,7 +1600,7 @@ AT_BISON_CHECK([[-o glr-regr17.c glr-regr17.y]], 0, [],
AT_COMPILE([glr-regr17])
AT_PARSER_CHECK([[./glr-regr17]], 0, [],
[1.1-2.3: syntax is ambiguous.
[1.1-2.2: syntax is ambiguous
])
AT_CLEANUP
@@ -1731,13 +1611,15 @@ AT_CLEANUP
## -------------------------------------------------------------##
AT_SETUP([Missed %merge type warnings when LHS type is declared later])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([glr-regr18.y],
[[%glr-parser
%{
#include <stdlib.h>
static void yyerror (char const *);
static int yylex ();
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%union {
@@ -1757,28 +1639,15 @@ sym3: %merge<merge> { $$ = 0; } ;
%type <type3> sym3;
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex ()
{
static int called;
if (called++)
abort ();
return 0;
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
int
main (void)
{
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o glr-regr18.c glr-regr18.y]], 1, [],
[glr-regr18.y:26.18-24: result type clash on merge function 'merge': <type2> != <type1>
@@ -1796,13 +1665,14 @@ AT_CLEANUP
AT_SETUP([Ambiguity reports])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%debug
@@ -1816,23 +1686,8 @@ start:
b: 'b';
d: /* nada. */;
%%
static int
yylex (void)
{
static char const input[] = "abc";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
return input[toknum++];
}
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYLEX_DEFINE(["abc"])[
]AT_YYERROR_DEFINE[
int
main (void)
{
@@ -1840,6 +1695,7 @@ main (void)
return !!yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]], 0, [],
[input.y: conflicts: 1 reduce/reduce
+141 -34
View File
@@ -19,47 +19,26 @@
AT_BANNER([[Parser Headers.]])
## ---------------------- ##
## %union and --defines. ##
## ---------------------- ##
AT_SETUP([%union and --defines])
AT_DATA([input.y],
[%union
{
int integer;
char *string ;
}
%%
exp: {};
])
AT_BISON_CHECK([--defines input.y])
AT_CLEANUP
## --------------------- ##
## Invalid CPP headers. ##
## --------------------- ##
# AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
# -------------------------------------
# AT_TEST_CPP_GUARD_H(BASE-NAME, [DIRECTIVES])
# --------------------------------------------
# FIXME: Much of this can be covered by calc.at.
m4_define([AT_TEST_CPP_GUARD_H],
[AT_SETUP([Invalid CPP guards: $1])
[AT_SETUP([Invalid CPP guards: $2 --defines=$1.h])
AT_BISON_OPTION_PUSHDEFS([$2])
# Possibly create inner directories.
dirname=`AS_DIRNAME([$1])`
AS_MKDIR_P([$dirname])
AT_DATA_GRAMMAR([$1.y],
[%{
[$2
%{
#include <$1.h>
void yyerror (const char *);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
%%
dummy:;
@@ -67,15 +46,18 @@ dummy:;
#include <$1.h>
])
AT_BISON_CHECK([--defines=$1.h --output=y.tab.c $1.y])
AT_BISON_CHECK([--defines=$1.h --output=$1.c $1.y])
AT_COMPILE([y.tab.o], [-I. -c y.tab.c])
AT_COMPILE([$1.o], [-I. -c $1.c])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
])
AT_TEST_CPP_GUARD_H([input/input])
AT_TEST_CPP_GUARD_H([9foo])
AT_TEST_CPP_GUARD_H([input/input], [%glr-parser])
AT_TEST_CPP_GUARD_H([9foo], [%glr-parser])
@@ -129,9 +111,134 @@ main (void)
# Link and execute, just to make sure everything is fine (and in
# particular, that MY_LLOC is indeed defined somewhere).
AT_COMPILE([caller.o], [-c caller.c])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([caller.o])
AT_COMPILE([input.o])
AT_COMPILE([caller], [caller.o input.o])
AT_PARSER_CHECK([./caller])
AT_CLEANUP
## ----------------- ##
## Several parsers. ##
## ----------------- ##
AT_SETUP([Several parsers])
# AT_TEST([PREFIX], [DIRECTIVES])
# -------------------------------
# Generate and compile to *.o. Make sure there is no YY* nor yy* in
# the header (but YYDEBUG and YYPARSE_PARAM).
m4_pushdef([AT_TEST],
[AT_BISON_OPTION_PUSHDEFS([%define api.prefix "$1_" $2])
AT_DATA_GRAMMAR([$1.AT_SKEL_CC_IF([yy], [y])],
[[%define api.prefix "$1_"
$2
%error-verbose
%union
{
int integer;
}
%{
#include <stdio.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%%
exp:
'x' '1' { printf ("x1\n"); }
| 'x' '2' { printf ("x2\n"); }
| 'x' '3' { printf ("x3\n"); }
| 'x' '4' { printf ("x4\n"); }
| 'x' '5' { printf ("x5\n"); }
| 'x' '6' { printf ("x6\n"); }
| 'x' '7' { printf ("x7\n"); }
| 'x' '8' { printf ("x8\n"); }
;
%%
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["$1"])[
]])
AT_BISON_CHECK([-d -o AT_SKEL_CC_IF([$1.cc $1.yy], [$1.c $1.y])])
# C++ output relies on namespaces and still uses yy a lot.
AT_SKEL_CC_IF([],
[AT_CHECK([$EGREP yy $1.h], [1])])
# Ignore comments. Ignore YYPARSE_PARAM (obsolete) and
# YYPUSH_MORE(_DEFINED)? (whose definition is constant).
#
# YYDEBUG (not renamed) can be read, but not changed.
AT_CHECK([[sed -ne 's,/\*[^*]*\*/,,g;s,//.*,,' \
-e '/YY/p' ]$1.AT_SKEL_CC_IF([hh], [h])[ |
$EGREP -wv 'YY(PARSE_PARAM|PUSH_MORE(_DEFINED)?)|(defined|if) YYDEBUG']],
[1])
AT_LANG_COMPILE([$1.o])
AT_CHECK([[echo "$1" >>expout]])
AT_BISON_OPTION_POPDEFS
])# AT_TEST
AT_DATA([main.cc],
[AT_DATA_SOURCE_PROLOGUE
[// If we are compiling with CC=$CXX, then do not load the C headers
// inside extern "C", since they were _not_ compiled this way.
#if ! CC_IS_CXX
extern "C"
{
#endif
#include "x1.h"
#include "x2.h"
#include "x3.h"
#include "x4.h"
#include "x6.h"
#include "x7.h"
#include "x8.h"
#if ! CC_IS_CXX
}
#endif
#include "x5.hh"
//#include "x6.hh"
#define RUN(S) \
do { \
int res = S; \
if (res) \
std::cerr << #S": " << res << std::endl; \
} while (false)
int
main (void)
{
RUN(x1_parse());
RUN(x2_parse());
RUN(x3_parse());
RUN(x4_parse());
x5_::parser p5;
RUN(p5.parse());
RUN(x6_parse());
RUN(x7_parse());
RUN(x8_parse());
// x6_::parser p6;
// RUN(p6.parse());
return 0;
}
]])# main.cc
AT_TEST([x1], [])
AT_TEST([x2], [%locations %debug])
AT_TEST([x3], [%glr-parser])
AT_TEST([x4], [%locations %debug %glr-parser])
AT_TEST([x5], [%locations %debug %language "c++"])
AT_TEST([x6], [%define api.pure])
AT_TEST([x7], [%define api.push-pull both])
AT_TEST([x8], [%define api.pure %define api.push-pull both])
#AT_TEST([x5], [%locations %language "c++" %glr-parser])
AT_COMPILE_CXX([parser], [[x[1-8].o -DCC_IS_CXX=$CC_IS_CXX main.cc]])
AT_CHECK([./parser], [0], [[expout]])
m4_popdef([AT_TEST])
AT_CLEANUP
+47 -19
View File
@@ -69,7 +69,7 @@ AT_CLEANUP
# _AT_UNUSED_VALUES_DECLARATIONS()
# --------------------------------------------
# --------------------------------
# Generate the token, type, and destructor
# declarations for the unused values tests.
@@ -391,7 +391,7 @@ AT_CLEANUP
AT_SETUP([Torturing the Scanner])
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y], [])
AT_BISON_CHECK([input.y], [1], [],
[[input.y:1.1: syntax error, unexpected end of file
@@ -442,6 +442,7 @@ char apostrophe = '\'';
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
%}
/* %{ and %} can be here too. */
@@ -468,8 +469,8 @@ char quote[] = "@:>@@:>@,";
%}
%{
static void yyerror (const char *s);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%type <ival> '@<:@'
@@ -501,7 +502,7 @@ value_as_yystype (value val)
res.ival = val;
return res;
}
]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -509,20 +510,13 @@ yylex (void)
#output "; /* "
*/
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
assert (toknum < sizeof input);
yylval = value_as_yystype (input[toknum]);
return input[toknum++];
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]])
# Pacify Emacs'font-lock-mode: "
# Pacify Emacs' font-lock-mode: "
AT_DATA([main.c],
[[typedef int value;
@@ -536,10 +530,11 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-d -v -o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([main.o], [-c main.c])
AT_COMPILE([input.o])
AT_COMPILE([main.o])
AT_COMPILE([input], [input.o main.o])
AT_PARSER_CHECK([./input], 0,
[[[@<:@],
@@ -621,14 +616,15 @@ AT_CLEANUP
AT_SETUP([Symbols])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%token WITH-DASH
%token WITHOUT_DASH "WITHOUT-DASH"
%token WITH.PERIOD
%token WITHOUT_PERIOD "WITHOUT.PERIOD"
%code {
void yyerror (char const *);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
%%
start: with-dash without_dash with.period without_period;
@@ -637,7 +633,10 @@ without_dash: "WITHOUT-DASH";
with.period: WITH.PERIOD;
without_period: "WITHOUT.PERIOD";
%%
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE[
]])
AT_BISON_OPTION_POPDEFS
# POSIX Yacc accept periods, but not dashes.
AT_BISON_CHECK([--yacc input.y], [1], [],
@@ -655,7 +654,7 @@ input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
AT_BISON_CHECK([-o input.c input.y])
# Make sure we don't export silly token identifiers with periods or dashes.
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
# Periods are genuine letters, they can start identifiers.
@@ -1341,3 +1340,32 @@ input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])
AT_CLEANUP
## ------------------------------------------------------ ##
## %name-prefix and %define api.prefix are incompatible. ##
## ------------------------------------------------------ ##
AT_SETUP([[%name-prefix and %define api.prefix are incompatible]])
# AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
# --------------------------------------------
m4_pushdef([AT_TEST],
[AT_DATA([[input.y]],
[[$1
%%
exp:;
]])
AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
[[$3: '%name-prefix' and '%define api.prefix' cannot be used together
]])
])
AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:2])
AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:2])
AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
m4_popdef([AT_TEST])
AT_CLEANUP
+5 -15
View File
@@ -32,6 +32,7 @@ AT_BANNER([[Java Calculator.]])
m4_define([_AT_DATA_JAVA_CALC_Y],
[m4_if([$1$2$3], $[1]$[2]$[3], [],
[m4_fatal([$0: Invalid arguments: $@])])dnl
AT_BISON_OPTION_PUSHDEFS([%language "Java" $4])
AT_DATA([Calc.y],
[[/* Infix notation calculator--calc */
%language "Java"
@@ -122,20 +123,8 @@ AT_LOCATION_IF([[
public Position getEndPos() {
return yypos;
}
public void yyerror (Calc.Location l, String s)
{
if (l == null)
System.err.println (s);
else
System.err.println (l + ": " + s);
}
]], [[
public void yyerror (String s)
{
System.err.println (s);
}
]])[
]AT_YYERROR_DEFINE[
Integer yylval;
@@ -211,11 +200,12 @@ class Position {
}
]])
AT_BISON_OPTION_POPDEFS
])# _AT_DATA_JAVA_CALC_Y
# AT_DATA_CALC_Y([BISON-OPTIONS])
# -------------------------------------------------
# -------------------------------
# Produce `calc.y'.
m4_define([AT_DATA_JAVA_CALC_Y],
[_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1])
@@ -224,7 +214,7 @@ m4_define([AT_DATA_JAVA_CALC_Y],
# _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT,
# [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
# ---------------------------------------------------------
# --------------------------------------------------------------
# Run `calc' on INPUT, and expect a `syntax error' message.
#
# If INPUT starts with a slash, it is used as absolute input file name,
+324 -128
View File
@@ -17,10 +17,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# We want a recent Autotest.
m4_version_prereq([2.58])
# m4_null_if(VAL, IF-TRUE, IF-FALSE)
# ----------------------------------
# If VAL evaluates to empty or 0, run IF-TRUE, otherwise IF-FALSE.
m4_define([m4_null_if],
[m4_case(m4_quote($1),
[0], [$2],
[], [$2],
[$3])])
## ------------- ##
## Basic tests. ##
## ------------- ##
@@ -45,6 +53,8 @@ m4_divert_text([PREPARE_TESTS],
{
for at_save_file in stderr experr expout
do
test ! -f at-bison-check-$at_save_file.bak ||
as_fn_error 1 "fatal error: back-up on top of a back-up"
test ! -f $at_save_file || mv $at_save_file at-bison-check-$at_save_file.bak
done
}
@@ -91,7 +101,8 @@ m4_popdef([AT_LOC_LAST_COLUMN])])
# AT_BISON_OPTION_PUSHDEFS([BISON-OPTIONS])
# -----------------------------------------
m4_define([AT_BISON_OPTION_PUSHDEFS],
[_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])
[m4_divert_text([KILL],
[_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])])
# _AT_BISON_OPTION_PUSHDEFS($1, $2, [BISON-OPTIONS])
@@ -108,8 +119,12 @@ m4_pushdef([AT_SKEL_CC_IF],
[m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
m4_pushdef([AT_SKEL_JAVA_IF],
[m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])])
m4_pushdef([AT_LANG],
[AT_SKEL_JAVA_IF([java],
[AT_SKEL_CC_IF([c++],
[c])])])
m4_pushdef([AT_GLR_IF],
[m4_bmatch([$3], [%glr-parser\|%skeleton "glr\.], [$1], [$2])])
[m4_bmatch([$3], [%glr-parser\|%skeleton "glr\..*"], [$1], [$2])])
m4_pushdef([AT_LALR1_CC_IF],
[AT_SKEL_CC_IF([AT_GLR_IF([$2], [$1])], [$2])])
m4_pushdef([AT_GLR_CC_IF],
@@ -134,9 +149,15 @@ m4_pushdef([AT_PURE_AND_LOC_IF],
m4_pushdef([AT_GLR_OR_PARAM_IF],
[m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])])
m4_pushdef([AT_NAME_PREFIX],
[m4_bmatch([$3], [%name-prefix ".*"],
[m4_bregexp([$3], [name-prefix "\([^"]*\)"], [\1])],
[m4_bmatch([$3], [\(%define api\.prefix\|%name-prefix\) ".*"],
[m4_bregexp([$3], [\(%define api\.prefix\|%name-prefix\) "\([^""]*\)"], [\2])],
[yy])])
m4_pushdef([AT_API_prefix],
[m4_bmatch([$3], [%define api\.prefix ".*"],
[m4_bregexp([$3], [%define api\.prefix "\([^""]*\)"], [\1])],
[yy])])
m4_pushdef([AT_API_PREFIX],
[m4_toupper(AT_API_prefix)])
# yyerror receives the location if %location & %pure & (%glr or %parse-param).
m4_pushdef([AT_YYERROR_ARG_LOC_IF],
[AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])],
@@ -155,27 +176,35 @@ m4_pushdef([AT_PURE_LEX_IF],
[AT_PURE_IF([$1],
[AT_SKEL_CC_IF([$1], [$2])])])
m4_pushdef([AT_YYSTYPE],
[AT_SKEL_CC_IF([AT_NAME_PREFIX[::parser::semantic_type]],
[AT_API_PREFIX[STYPE]])])
m4_pushdef([AT_YYLTYPE],
[AT_SKEL_CC_IF([AT_NAME_PREFIX[::parser::location_type]],
[AT_API_PREFIX[LTYPE]])])
AT_PURE_LEX_IF(
[m4_pushdef([AT_LOC], [(*llocp)])
m4_pushdef([AT_VAL], [(*lvalp)])
m4_pushdef([AT_LEX_FORMALS],
[YYSTYPE *lvalp[]AT_LOCATION_IF([, YYLTYPE *llocp])])
m4_pushdef([AT_LEX_ARGS],
m4_pushdef([AT_YYLEX_FORMALS],
[AT_YYSTYPE *lvalp[]AT_LOCATION_IF([, AT_YYLTYPE *llocp])])
m4_pushdef([AT_YYLEX_ARGS],
[lvalp[]AT_LOCATION_IF([, llocp])])
m4_pushdef([AT_USE_LEX_ARGS],
[(void) lvalp;AT_LOCATION_IF([(void) llocp])])
m4_pushdef([AT_LEX_PRE_FORMALS],
[AT_LEX_FORMALS, ])
m4_pushdef([AT_LEX_PRE_ARGS],
[AT_LEX_ARGS, ])
m4_pushdef([AT_YYLEX_PRE_FORMALS],
[AT_YYLEX_FORMALS, ])
m4_pushdef([AT_YYLEX_PRE_ARGS],
[AT_YYLEX_ARGS, ])
],
[m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
m4_pushdef([AT_LEX_FORMALS], [void])
m4_pushdef([AT_LEX_ARGS], [])
m4_pushdef([AT_YYLEX_FORMALS], [void])
m4_pushdef([AT_YYLEX_ARGS], [])
m4_pushdef([AT_USE_LEX_ARGS], [])
m4_pushdef([AT_LEX_PRE_FORMALS], [])
m4_pushdef([AT_LEX_PRE_ARGS], [])
m4_pushdef([AT_YYLEX_PRE_FORMALS], [])
m4_pushdef([AT_YYLEX_PRE_ARGS], [])
])
# Handle the different types of location components.
@@ -192,16 +221,21 @@ AT_SKEL_CC_IF(
# AT_BISON_OPTION_POPDEFS
# -----------------------
m4_define([AT_BISON_OPTION_POPDEFS],
[m4_popdef([AT_LEX_PRE_ARGS])
m4_popdef([AT_LEX_PRE_FORMALS])
[m4_divert_text([KILL],
[m4_popdef([AT_YYLEX_PRE_ARGS])
m4_popdef([AT_YYLEX_PRE_FORMALS])
m4_popdef([AT_USE_LEX_ARGS])
m4_popdef([AT_LEX_ARGS])
m4_popdef([AT_LEX_FORMALS])
m4_popdef([AT_YYLEX_ARGS])
m4_popdef([AT_YYLEX_FORMALS])
m4_popdef([AT_YYLTYPE])
m4_popdef([AT_YYSTYPE])
m4_popdef([AT_VAL])
m4_popdef([AT_LOC])
m4_popdef([AT_PURE_LEX_IF])
m4_popdef([AT_YYERROR_SEES_LOC_IF])
m4_popdef([AT_YYERROR_ARG_LOC_IF])
m4_popdef([AT_API_PREFIX])
m4_popdef([AT_API_prefix])
m4_popdef([AT_NAME_PREFIX])
m4_popdef([AT_GLR_OR_PARAM_IF])
m4_popdef([AT_PURE_AND_LOC_IF])
@@ -212,11 +246,12 @@ m4_popdef([AT_LEXPARAM_IF])
m4_popdef([AT_YACC_IF])
m4_popdef([AT_GLR_IF])
m4_popdef([AT_SKEL_CC_IF])
m4_popdef([AT_LANG])
m4_popdef([AT_SKEL_JAVA_IF])
m4_popdef([AT_GLR_CC_IF])
m4_popdef([AT_LALR1_CC_IF])
m4_popdef([AT_DEFINES_IF])
AT_LOC_POPDEF
AT_LOC_POPDEF])dnl
])# AT_BISON_OPTION_POPDEFS
@@ -267,8 +302,122 @@ m4_define([AT_DATA_GRAMMAR],
$2])
])
# AT_YYLEX_PROTOTYPE
# AT_YYLEX_DECLARE_EXTERN
# AT_YYLEX_DECLARE
# AT_YYLEX_DEFINE([INPUT], [ACTION])
# ----------------------------------
# INPUT can be empty, or in double quotes, or a list (in braces).
# ACTION may compute yylval for instance, using "res" as token type,
# and "toknum" as the number of calls to yylex (starting at 0).
m4_define([AT_YYLEX_PROTOTYPE],
[int AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
])
m4_define([AT_YYLEX_DECLARE_EXTERN],
[AT_YYLEX_PROTOTYPE;dnl
])
m4_define([AT_YYLEX_DECLARE],
[static AT_YYLEX_DECLARE_EXTERN[]dnl
])
m4_define([AT_YYLEX_DEFINE],
[[#include <assert.h>
static
]AT_YYLEX_PROTOTYPE[
{
]m4_bmatch([$1], [^\(".*"\)?$],
[[static char const input[] = ]m4_default([$1], [""])],
[[static int const input[] = ]$1])[;
static size_t toknum = 0;
int res;
]AT_USE_LEX_ARGS[;
assert (toknum < sizeof input);
res = input[toknum++];
]$2[;]AT_LOCATION_IF([[
]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[
return res;
}]dnl
])
# AT_YYERROR_PROTOTYPE
# AT_YYERROR_DECLARE_EXTERN
# AT_YYERROR_DECLARE
# AT_YYERROR_DEFINE
# -------------------------
# Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
m4_define([AT_YYERROR_FORMALS],
[m4_case(AT_LANG,
[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])[const char *msg]])[]dnl
])
m4_define([AT_YYERROR_PROTOTYPE],
[m4_case(AT_LANG,
[c], [[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])[]dnl
])
m4_define([AT_YYERROR_DECLARE_EXTERN],
[m4_case(AT_LANG,
[c], [AT_YYERROR_PROTOTYPE;])[]dnl
])
m4_define([AT_YYERROR_DECLARE],
[m4_case(AT_LANG,
[c], [static AT_YYERROR_DECLARE_EXTERN])[]dnl
])
m4_define([AT_YYERROR_DEFINE],
[m4_case(AT_LANG,
[c], [[#include <stdio.h>
/* A C error reporting function. */
static
]AT_YYERROR_PROTOTYPE[
{
]AT_YYERROR_SEES_LOC_IF([[
fprintf (stderr, "%d.%d",
]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[);
if (]AT_LOC_FIRST_LINE[ != ]AT_LOC_LAST_LINE[)
fprintf (stderr, "-%d.%d",
]AT_LOC_LAST_LINE[, ]AT_LOC_LAST_COLUMN[ - 1);
else if (]AT_LOC_FIRST_COLUMN[ != ]AT_LOC_LAST_COLUMN[ - 1)
fprintf (stderr, "-%d",
]AT_LOC_LAST_COLUMN[ - 1);
fprintf (stderr, ": ");]])[
fprintf (stderr, "%s\n", msg);
}]],
[c++], [[/* A C++ error reporting function. */
void
]AT_NAME_PREFIX[::parser::error (const location_type& l, const std::string& m)
{
(void) l;
std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << std::endl;
}]],
[java], [AT_LOCATION_IF([[public void yyerror (Calc.Location l, String s)
{
if (l == null)
System.err.println (s);
else
System.err.println (l + ": " + s);
}
]], [[
public void yyerror (String s)
{
System.err.println (s);
}]])])dnl
])
## --------------- ##
## Running Bison. ##
## --------------- ##
# AT_BISON_CHECK(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
# -------------------------------------------------
# High-level routine that may call bison several times, under different
# conditions.
#
# Check Bison by invoking `bison BISON_ARGS'. BISON_ARGS should not contain
# shell constructs (such as redirection or pipes) that would prevent
# appending additional command-line arguments for bison. OTHER_AT_CHECK_ARGS
@@ -289,83 +438,93 @@ $2])
#
# 4. If stderr contains a warning, -Wnone and --warnings=none suppress it.
m4_define([AT_BISON_CHECK],
[m4_if(m4_quote($2), [0], [AT_BISON_CHECK_XML($@)],
m4_quote($2), [], [AT_BISON_CHECK_XML($@)])
[m4_null_if([$2], [AT_BISON_CHECK_XML($@)])
AT_BISON_CHECK_NO_XML($@)])
m4_define([AT_BISON_WERROR_MSG],
[[bison: warnings being treated as errors]])
# AT_BISON_CHECK_(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
# --------------------------------------------------
# Low-level macro to run bison once.
m4_define([AT_BISON_CHECK_],
[AT_CHECK(AT_QUELL_VALGRIND[[ bison ]]$@)])
# AT_BISON_CHECK_WARNINGS(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
# ----------------------------------------------------------
# Check that warnings (if some are expected) are correctly
# turned into errors with -Werror, etc.
m4_define([AT_BISON_CHECK_WARNINGS],
[m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
[m4_null_if([$2], [AT_BISON_CHECK_WARNINGS_($@)])])])
m4_define([AT_BISON_CHECK_WARNINGS_],
[[# Defining POSIXLY_CORRECT causes bison to complain if options
# are added after the grammar file name, so skip these checks
# in that case.
if test -z "${POSIXLY_CORRECT+set}"; then
]AT_SAVE_SPECIAL_FILES[
# To avoid expanding it repeatedly, store specified stdout.
]AT_DATA([expout], [$3])[
# Run with -Werror.
]AT_BISON_CHECK_([$1[ -Werror]], [[1]], [expout], [stderr])[
# Build expected stderr up to and including the "warnings being
# treated as errors" message.
]AT_DATA([[at-bison-check-warnings]], [$4])[
at_bison_check_first=`sed -n \
'/: warning: /{=;q;}' at-bison-check-warnings`
: ${at_bison_check_first:=1}
at_bison_check_first_tmp=`sed -n \
'/conflicts: [0-9].*reduce$/{=;q;}' at-bison-check-warnings`
: ${at_bison_check_first_tmp:=1}
if test $at_bison_check_first_tmp -lt $at_bison_check_first; then
at_bison_check_first=$at_bison_check_first_tmp
fi
if test $at_bison_check_first -gt 1; then
sed -n "1,`expr $at_bison_check_first - 1`"p \
at-bison-check-warnings > experr
fi
echo ']AT_BISON_WERROR_MSG[' >> experr
# Finish building expected stderr and check. Unlike warnings,
# complaints cause bison to exit early. Thus, with -Werror, bison
# does not necessarily report all warnings that it does without
# -Werror, but it at least reports one.
at_bison_check_last=`sed -n '$=' stderr`
: ${at_bison_check_last:=1}
at_bison_check_last=`expr $at_bison_check_last - 1`
sed -n "$at_bison_check_first,$at_bison_check_last"p \
at-bison-check-warnings >> experr
]AT_CHECK([[sed 's,.*/\(]AT_BISON_WERROR_MSG[\)$,\1,' \
stderr 1>&2]], [[0]], [[]], [experr])[
# Now check --warnings=error.
cp stderr experr
]AT_BISON_CHECK_([$1[ --warnings=error]], [[1]], [expout], [experr])[
# Now check -Wnone and --warnings=none by making sure that
# -Werror doesn't change the exit status when -Wnone or
# --warnings=none is specified.
]AT_BISON_CHECK_([$1[ -Wnone -Werror]], [[0]], [expout])[
]AT_BISON_CHECK_([$1[ --warnings=none -Werror]], [[0]], [expout])[
]AT_RESTORE_SPECIAL_FILES[
fi]dnl
])
# AT_BISON_CHECK_NO_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
# --------------------------------------------------------
# Same as AT_BISON_CHECK except don't perform XML/XSLT checks. This is useful
# when a tortured grammar's XML is known to be too large for xsltproc to
# handle.
m4_define([AT_BISON_CHECK_NO_XML],
[AT_CHECK(m4_if(m4_quote($2), [0], [], m4_quote($2), [], [],
[AT_QUELL_VALGRIND ])[[bison ]]$@)
m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
m4_quote(m4_if(m4_quote($2), [], [0], [$2])), [0], [[
# Defining POSIXLY_CORRECT causes bison to complain if options
# are added after the grammar file name, so skip these checks
# in that case.
if test -z "${POSIXLY_CORRECT+set}"; then
]AT_SAVE_SPECIAL_FILES[
# To avoid expanding it repeatedly, store specified stdout.
]AT_DATA([expout], [$3])[
# Run with -Werror.
]AT_CHECK(AT_QUELL_VALGRIND[[ bison ]$1[ -Werror]],
[[1]], [expout], [stderr])[
# Build expected stderr up to and including the "warnings being
# treated as errors" message.
]AT_DATA([[at-bison-check-warnings]], [$4])[
at_bison_check_first=`sed -n \
'/: warning: /{=;q;}' at-bison-check-warnings`
: ${at_bison_check_first:=1}
at_bison_check_first_tmp=`sed -n \
'/conflicts: [0-9].*reduce$/{=;q;}' at-bison-check-warnings`
: ${at_bison_check_first_tmp:=1}
if test $at_bison_check_first_tmp -lt $at_bison_check_first; then
at_bison_check_first=$at_bison_check_first_tmp
fi
if test $at_bison_check_first -gt 1; then
sed -n "1,`expr $at_bison_check_first - 1`"p \
at-bison-check-warnings > experr
fi
echo ']AT_BISON_WERROR_MSG[' >> experr
# Finish building expected stderr and check. Unlike warnings,
# complaints cause bison to exit early. Thus, with -Werror, bison
# does not necessarily report all warnings that it does without
# -Werror, but it at least reports one.
at_bison_check_last=`sed -n '$=' stderr`
: ${at_bison_check_last:=1}
at_bison_check_last=`expr $at_bison_check_last - 1`
sed -n "$at_bison_check_first,$at_bison_check_last"p \
at-bison-check-warnings >> experr
]AT_CHECK([[sed 's,.*/\(]AT_BISON_WERROR_MSG[\)$,\1,' \
stderr 1>&2]], [[0]], [[]], [experr])[
# Now check --warnings=error.
cp stderr experr
]AT_CHECK(AT_QUELL_VALGRIND[[ bison ]$1[ --warnings=error]],
[[1]], [expout], [experr])[
# Now check -Wnone and --warnings=none by making sure that
# -Werror doesn't change the exit status when -Wnone or
# --warnings=none is specified.
]AT_CHECK(AT_QUELL_VALGRIND[[ bison ]$1[ -Wnone -Werror]],
[[0]], [expout])[
]AT_CHECK(AT_QUELL_VALGRIND[[ bison ]$1[ --warnings=none \
-Werror]], [[0]], [expout])[
]AT_RESTORE_SPECIAL_FILES[
fi
]])
])
[AT_CHECK(m4_null_if([$2], [], [AT_QUELL_VALGRIND ])[[bison ]]$@)
AT_BISON_CHECK_WARNINGS($@)])
# AT_BISON_CHECK_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
# -----------------------------------------------------
@@ -383,11 +542,11 @@ m4_define([AT_BISON_CHECK_XML],
[--xml=[^][ ]*], [])])dnl
# Don't combine these Bison invocations since we want to be sure that
# --report=all isn't required to get the full XML file.
AT_CHECK([[bison --report=all --report-file=xml-tests/test.output \
--graph=xml-tests/test.dot ]]AT_BISON_ARGS,
[[0]], [ignore], [ignore])
AT_CHECK([[bison --xml=xml-tests/test.xml ]]AT_BISON_ARGS,
[[0]], [ignore], [ignore])
AT_BISON_CHECK_([[--report=all --report-file=xml-tests/test.output \
--graph=xml-tests/test.dot ]]AT_BISON_ARGS,
[[0]], [ignore], [ignore])
AT_BISON_CHECK_([[--xml=xml-tests/test.xml ]]AT_BISON_ARGS,
[[0]], [ignore], [ignore])
m4_popdef([AT_BISON_ARGS])dnl
[cp xml-tests/test.output expout]
AT_CHECK([[$XSLTPROC \
@@ -415,6 +574,8 @@ m4_define([AT_BISON_CHECK_XML],
m4_define([AT_QUELL_VALGRIND],
[[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary --show-reachable=no"; export VALGRIND_OPTS;]]])
## ------------------------ ##
## Compiling C, C++ Files. ##
## ------------------------ ##
@@ -422,21 +583,37 @@ m4_define([AT_QUELL_VALGRIND],
# AT_COMPILE(OUTPUT, [SOURCES = OUTPUT.c])
# ----------------------------------------
# Compile SOURCES into OUTPUT. If OUTPUT does not contain '.',
# assume that we are linking too; this is a hack.
# Compile SOURCES into OUTPUT.
#
# If OUTPUT does not contain '.', assume that we are linking too,
# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
# with trailing .o removed, and ".c" appended.
m4_define([AT_COMPILE],
[AT_CHECK([$CC $CFLAGS $CPPFLAGS m4_bmatch([$1], [[.]], [], [$LDFLAGS ])-o $1 m4_default([$2], [$1.c])[]m4_bmatch([$1], [[.]], [], [ $LIBS])],
[AT_CHECK(m4_join([ ],
[$CC $CFLAGS $CPPFLAGS],
[m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
[-o $1],
[m4_default([$2], [m4_bpatsubst([$1], [\.o$]).c])],
[m4_bmatch([$1], [[.]], [], [$LIBS])]),
0, [ignore], [ignore])])
# AT_COMPILE_CXX(OUTPUT, [SOURCES = OUTPUT.cc])
# --------------------------------------------
# Compile SOURCES into OUTPUT. If OUTPUT does not contain '.',
# assume that we are linking too; this is a hack.
# If the C++ compiler does not work, ignore the test.
# ---------------------------------------------
# Compile SOURCES into OUTPUT. If the C++ compiler does not work,
# ignore the test.
#
# If OUTPUT does not contain '.', assume that we are linking too,
# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
# with trailing .o removed, and ".cc" appended.
m4_define([AT_COMPILE_CXX],
[AT_KEYWORDS(c++)
AT_CHECK([$BISON_CXX_WORKS], 0, ignore, ignore)
AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS m4_bmatch([$1], [[.]], [], [$LDFLAGS ])-o $1 m4_default([$2], [$1.cc])[]m4_bmatch([$1], [[.]], [], [ $LIBS])],
AT_CHECK(m4_join([ ],
[$CXX $CXXFLAGS $CPPFLAGS],
[m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
[-o $1],
[m4_default([$2], [m4_bpatsubst([$1], [\.o$]).cc])],
[m4_bmatch([$1], [[.]], [], [$LIBS])]),
0, [ignore], [ignore])])
# AT_JAVA_COMPILE(SOURCES)
@@ -445,32 +622,56 @@ AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS m4_bmatch([$1], [[.]], [], [$LDFLAGS ])-o $1
# is not installed.
m4_define([AT_JAVA_COMPILE],
[AT_KEYWORDS(java)
AT_CHECK([[test -n "$CONF_JAVA" || exit 77
test -n "$CONF_JAVAC" || exit 77]])
AT_SKIP_IF([[test -z "$CONF_JAVAC"]])
AT_SKIP_IF([[test -z "$CONF_JAVA"]])
AT_CHECK([[$SHELL ../../../javacomp.sh ]$1],
[[0]], [ignore], [ignore])])
# AT_FULL_COMPILE(OUTPUT, [OTHER])
# --------------------------------
# AT_LANG_COMPILE(OUTPUT, [SOURCES = OUTPUT.c]
# --------------------------------------------
# Compile SOURCES into OUTPUT. Skip if compiler does not work.
#
# If OUTPUT does not contain '.', assume that we are linking too,
# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
# with trailing .o removed, and ".c"/".cc" appended.
m4_define([AT_LANG_COMPILE],
[m4_case(AT_LANG,
[c], [AT_COMPILE([$1], [$2])],
[c++], [AT_COMPILE_CXX([$1], [$2])],
[java], [AT_JAVA_COMPILE([$1.java], [$2])],
[m4_fatal([unknown language: ]m4_defn([AT_LANG]))])[]dnl
])
# AT_FULL_COMPILE(OUTPUT, [OTHER1], [OTHER2])
# -------------------------------------------
# Compile OUTPUT.y to OUTPUT.c, OUTPUT.cc, or OUTPUT.java, and then
# compile it to OUTPUT or OUTPUT.class. If OTHER is specified, compile
# OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or
# OUTPUT.java along with it. Relies on AT_SKEL_CC_IF and
# AT_SKEL_JAVA_IF.
m4_define([AT_FULL_COMPILE], [
AT_SKEL_JAVA_IF([
AT_BISON_CHECK([[-o ]$1[.java ]$1[.y]])
AT_JAVA_COMPILE([$1[.java]]m4_ifval($2,
[[$1[.java ]$1[-]$2[.java]]]))
], [
AT_SKEL_CC_IF([
AT_BISON_CHECK([[-o ]$1[.cc ]$1[.y]])
AT_COMPILE_CXX([$1]m4_ifval($2, [, [$1[.cc ]$1[-]$2[.cc]]]))
], [
AT_BISON_CHECK([[-o ]$1[.c ]$1[.y]])
AT_COMPILE([$1]m4_ifval($2, [, [$1[.c ]$1[-]$2[.c]]]))
])
])
m4_define([AT_FULL_COMPILE],
[m4_case(AT_LANG,
[java],
[AT_BISON_CHECK([-o $1.java $1.y])
AT_LANG_COMPILE([$1],
m4_join([ ],
[$1.java],
m4_ifval($2, [[$1-$2.java]]),
m4_ifval($3, [[$1-$3.java]])))],
[c++],
[AT_BISON_CHECK([-o $1.cc $1.y])
AT_LANG_COMPILE([$1],
m4_join([ ],
[$1.cc],
m4_ifval($2, [[$1-$2.cc]]),
m4_ifval($3, [[$1-$3.cc]])))],
[c],
[AT_BISON_CHECK([-o $1.c $1.y])
AT_LANG_COMPILE([$1],
m4_join([ ],
[$1.c],
m4_ifval($2, [[$1-$2.c]]),
m4_ifval($3, [[$1-$3.c]])))])
])
@@ -577,12 +778,12 @@ m4_define([AT_TEST_TABLES_AND_PARSE],
[m4_pushdef([AT_COND_CASE], [m4_case([$2], $][@)])
AT_SETUP([$1])
AT_BISON_OPTION_PUSHDEFS([$4])
AT_DATA_GRAMMAR([[input.y]],
[[%code {
#include <stdio.h>
static void yyerror (char const *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
]$4[
@@ -592,13 +793,7 @@ AT_DATA_GRAMMAR([[input.y]],
]$5[
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
static int
yylex (void)
{
@@ -654,6 +849,7 @@ AT_PARSER_CHECK([[./input]],
m4_ifval([$11], [m4_dquote($11)]),
m4_ifval([$12], [m4_dquote($12)]))
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
m4_popdef([AT_COND_CASE])])
+13 -17
View File
@@ -19,7 +19,7 @@
AT_BANNER([[Named references tests.]])
AT_SETUP([Tutorial calculator])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([test.y],
[[
%{
@@ -33,8 +33,8 @@ FILE *input;
static semantic_value global_result = 0;
static int global_count = 0;
static int power (int base, int exponent);
static void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%union
@@ -83,12 +83,7 @@ exp:
| '-' error { $$ = 0; YYERROR; }
;
%%
static void yyerror (const char *s)
{
fprintf (stderr, "%s\n", s);
}
]AT_YYERROR_DEFINE[
static int get_char (void)
{
int res = getc (input);
@@ -119,7 +114,8 @@ static int read_signed_integer (void)
return sign * n;
}
int yylex (void)
static int
yylex (void)
{
int c;
/* Skip white space. */
@@ -166,10 +162,8 @@ int main (int argc, const char **argv)
}
status = yyparse ();
fclose (input);
if (global_result != result)
abort ();
if (global_count != count)
abort ();
assert (global_result == result);
assert (global_count == count);
return status;
}
]])
@@ -190,6 +184,7 @@ AT_DATA([input.txt],
AT_BISON_CHECK([-o test.c test.y])
AT_COMPILE([[test]])
AT_PARSER_CHECK([./test input.txt], 0, [], [stderr])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -198,13 +193,13 @@ AT_CLEANUP
AT_SETUP([Undefined and ambiguous references])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([test.y],
[[
%{
static int power (int base, int exponent);
static void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%union
@@ -268,6 +263,7 @@ test.y:55.3-53: symbol not found in production: r12
test.y:56.29-33: invalid reference: '$expo'
test.y:56.3-46: symbol not found in production: expo
]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
#######################################################################
+5 -3
View File
@@ -176,10 +176,11 @@ AT_CHECK_CONFLICTING_OUTPUT([foo.y], [], [-o foo.y],
# AT_CHECK_OUTPUT_FILE_NAME(FILE-NAME-PREFIX, [ADDITIONAL-TESTS])
# -----------------------------------------------------------------------------
# ---------------------------------------------------------------
m4_define([AT_CHECK_OUTPUT_FILE_NAME],
[AT_SETUP([Output file name: $1])
AT_BISON_OPTION_PUSHDEFS
# Skip if platform doesn't support file name. For example, Cygwin
# doesn't support file names containing ":" or "\".
AT_CHECK([[touch "]AS_ESCAPE([$1[.tmp]])[" || exit 77]])
@@ -187,8 +188,8 @@ AT_CHECK([[touch "]AS_ESCAPE([$1[.tmp]])[" || exit 77]])
AT_DATA_GRAMMAR([glr.y],
[[%glr-parser
%code {
int yylex (void);
void yyerror (const char *);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
}
%%
start: {};
@@ -209,6 +210,7 @@ AT_CHECK([ls "AS_ESCAPE([$1.c])" "AS_ESCAPE([$1.h])"], [], [ignore])
AT_COMPILE_CXX([cxx.o], [-c "AS_ESCAPE([$1.c])"])
$2
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
])
+15 -25
View File
@@ -24,17 +24,18 @@ AT_BANNER([[Push Parsing Tests]])
AT_SETUP([[Memory Leak for Early Deletion]])
# Requires Valgrind.
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[
%{
#include <assert.h>
#include <stdio.h>
#define YYINITDEPTH 1
void yyerror (char const *msg);
]AT_YYERROR_DECLARE[
%}
%define api.pure %define api.push-pull push
%define api.pure
%define api.push-pull push
%%
@@ -42,11 +43,7 @@ start: 'a' 'b' 'c' ;
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
int
main (void)
@@ -71,6 +68,7 @@ main (void)
return 0;
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
@@ -85,13 +83,14 @@ AT_CLEANUP
AT_SETUP([[Multiple impure instances]])
m4_pushdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK], [
AT_BISON_OPTION_PUSHDEFS([%define api.push-pull $1])
AT_DATA_GRAMMAR([[input.y]],
[[
%{
#include <assert.h>
#include <stdio.h>
void yyerror (char const *msg);
int yylex (void);
]AT_YYERROR_DECLARE[
]m4_if([$1], [[both]], [AT_YYLEX_DECLARE([])])[
%}
%define api.push-pull ]$1[
@@ -101,28 +100,16 @@ AT_DATA_GRAMMAR([[input.y]],
start: ;
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
int
yylex (void)
{
return 0;
}
]AT_YYERROR_DEFINE[
]m4_if([$1], [[both]], [AT_YYLEX_DEFINE])[
int
main (void)
{
yypstate *ps;
int i;
for (i = 0; i < 2; ++i)
{
ps = yypstate_new ();
yypstate *ps = yypstate_new ();
assert (ps);
assert (yypstate_new () == YY_NULL);
]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
@@ -140,6 +127,7 @@ main (void)
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
AT_PARSER_CHECK([[./input]])
AT_BISON_OPTION_POPDEFS
])
AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[both]])
@@ -155,12 +143,14 @@ AT_CLEANUP
AT_SETUP([[Unsupported Skeletons]])
AT_BISON_OPTION_PUSHDEFS
AT_DATA([[input.y]],
[[%glr-parser
%define api.push-pull push
%%
start: ;
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[input.y]], [[1]], [],
[[input.y:2.9-21: %define variable 'api.push-pull' is not used
+107 -195
View File
@@ -24,10 +24,11 @@ AT_BANNER([[Regression tests.]])
AT_SETUP([Trivial grammars])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%{
void yyerror (char const *);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
#define YYSTYPE int *
%}
@@ -37,9 +38,10 @@ int yylex (void);
program: 'x';
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
AT_CLEANUP
@@ -52,10 +54,11 @@ AT_CLEANUP
AT_SETUP([YYSTYPE typedef])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%{
void yyerror (char const *);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
typedef union { char const *val; } YYSTYPE;
%}
@@ -65,9 +68,10 @@ typedef union { char const *val; } YYSTYPE;
program: { $$ = ""; };
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_CLEANUP
@@ -83,10 +87,11 @@ AT_SETUP([Early token definitions with --yacc])
# Found in GCJ: they expect the tokens to be defined before the user
# prologue, so that they can use the token definitions in it.
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%{
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
%union
@@ -103,9 +108,10 @@ int yylex (void);
exp: MY_TOKEN;
%%
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-y -o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_CLEANUP
@@ -121,11 +127,12 @@ AT_SETUP([Early token definitions without --yacc])
# Found in GCJ: they expect the tokens to be defined before the user
# prologue, so that they can use the token definitions in it.
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%{
#include <stdio.h>
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
void print_my_token (void);
%}
@@ -146,9 +153,10 @@ print_my_token (void)
exp: MY_TOKEN;
%%
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_CLEANUP
@@ -161,6 +169,7 @@ AT_CLEANUP
AT_SETUP([Braces parsing])
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y],
[[/* Bison used to swallow the character after '}'. */
@@ -168,6 +177,7 @@ AT_DATA([input.y],
exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
%%
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-v -o input.c input.y])
@@ -183,6 +193,7 @@ AT_CLEANUP
AT_SETUP([Duplicate string])
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y],
[[/* 'Bison -v' used to dump core when two tokens are defined with the same
string, as LE and GE below. */
@@ -195,6 +206,7 @@ AT_DATA([input.y],
exp: '(' exp ')' | NUM ;
%%
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-v -o input.c input.y], 0, [],
[[input.y:6.8-14: warning: symbol "<=" used more than once as a literal string
@@ -211,6 +223,7 @@ AT_SETUP([Rule Line Numbers])
AT_KEYWORDS([report])
AT_BISON_OPTION_PUSHDEFS
AT_DATA([input.y],
[[%%
expr:
@@ -240,6 +253,7 @@ expr:
};
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c -v input.y])
@@ -428,13 +442,14 @@ AT_CLEANUP
AT_SETUP([Token definitions])
AT_BISON_OPTION_PUSHDEFS
# Bison managed, when fed with '%token 'f' "f"' to #define 'f'!
AT_DATA_GRAMMAR([input.y],
[%{
#include <stdlib.h>
#include <stdio.h>
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
[%error-verbose
%token MYEOF 0 "end of file"
@@ -447,20 +462,8 @@ int yylex (void);
%%
exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
%%
void
yyerror (char const *s)
{
fprintf (stderr, "%s\n", s);
}
int
yylex (void)
{
static int called;
if (called++)
abort ();
return SPECIAL;
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE([{ SPECIAL }])[
int
main (void)
@@ -468,6 +471,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
# Checking the warning message guarantees that the trigraph "??!" isn't
# unnecessarily escaped here even though it would need to be if encoded in a
@@ -498,22 +502,24 @@ AT_CLEANUP
AT_SETUP([Characters Escapes])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[%{
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
[%%
exp:
'\'' "\'"
| '\"' "\""
| '"' "'"
| '"' "'" /* Pacify font-lock-mode: ". */
;
]])
# Pacify font-lock-mode: "
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_CLEANUP
@@ -832,13 +838,11 @@ AT_CLEANUP
# so that possible bound checking compilers could check all the skeletons.
m4_define([_AT_DATA_DANCER_Y],
[AT_DATA_GRAMMAR([dancer.y],
[%{
static int yylex (AT_LALR1_CC_IF([int *], [void]));
AT_LALR1_CC_IF([],
[#include <stdlib.h>
#include <stdio.h>
static void yyerror (const char *);])
%}
[[%code provides
{
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
$1
%token ARROW INVALID NUMBER STRING DATA
%defines
@@ -883,15 +887,10 @@ member: STRING
| INVALID
;
%%
AT_LALR1_CC_IF(
[/* A C++ error reporting function. */
void
yy::parser::error (const location&, const std::string& m)
{
std::cerr << m << std::endl;
}
int
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE([":"])[
]AT_LALR1_CC_IF(
[int
yyparse ()
{
yy::parser parser;
@@ -900,33 +899,14 @@ yyparse ()
#endif
return parser.parse ();
}
],
[static void
yyerror (const char *s)
{
fprintf (stderr, "%s\n", s);
}])
static int
yylex (AT_LALR1_CC_IF([int *lval], [void]))
[{
static int const tokens[] =
{
':', -1
};
static size_t toknum;
]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
if (! (toknum < sizeof tokens / sizeof *tokens))
abort ();
return tokens[toknum++];
}]
])[
int
main (void)
{
return yyparse ();
}
])
]])
])# _AT_DATA_DANCER_Y
@@ -960,12 +940,12 @@ AT_CHECK_DANCER([%skeleton "lalr1.cc"])
# --------------------------------
m4_define([_AT_DATA_EXPECT2_Y],
[AT_DATA_GRAMMAR([expect2.y],
[%{
static int yylex (AT_LALR1_CC_IF([int *], [void]));
[[%{
static int yylex (]AT_LALR1_CC_IF([int *], [void]));
AT_LALR1_CC_IF([],
[#include <stdio.h>
[[#include <stdio.h>
#include <stdlib.h>
static void yyerror (const char *);])
]AT_YYERROR_DECLARE])[
%}
$1
%defines
@@ -982,52 +962,41 @@ e: e '+' t | t;
t: A | B;
%%
AT_LALR1_CC_IF(
[/* A C++ error reporting function. */
void
yy::parser::error (const location&, const std::string& m)
{
std::cerr << m << std::endl;
}
int
]AT_YYERROR_DEFINE[
]AT_LALR1_CC_IF(
[int
yyparse ()
{
yy::parser parser;
return parser.parse ();
}
],
[static void
yyerror (const char *s)
{
fprintf (stderr, "%s\n", s);
}])
])[
#include <assert.h>
static int
yylex (AT_LALR1_CC_IF([int *lval], [void]))
[{
yylex (]AT_LALR1_CC_IF([int *lval], [void])[)
{
static int const tokens[] =
{
1000, '+', '+', -1
};
static size_t toknum;
]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
if (! (toknum < sizeof tokens / sizeof *tokens))
abort ();
assert (toknum < sizeof tokens / sizeof *tokens);
return tokens[toknum++];
}]
}
int
main (void)
{
return yyparse ();
}
])
]])
])# _AT_DATA_EXPECT2_Y
# AT_CHECK_EXPECT2(BISON-OPTIONS)
# ------------------------------
# -------------------------------
# Generate the grammar, compile it, run it.
m4_define([AT_CHECK_EXPECT2],
[AT_SETUP([Expecting two tokens $1])
@@ -1056,12 +1025,12 @@ AT_SETUP([Braced code in declaration in rules section])
# Bison once mistook braced code in a declaration in the rules section to be a
# rule action.
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%{
#include <stdio.h>
static void yyerror (char const *msg);
static int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%error-verbose
@@ -1079,18 +1048,8 @@ start:
%printer { fprintf (yyoutput, "PRINTER"); } 'a';
%%
static void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
static int
yylex (void)
{
return 'a';
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["a"])[
int
main (void)
@@ -1099,6 +1058,7 @@ main (void)
return !yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-t -o input.c input.y])
AT_COMPILE([input])
@@ -1196,12 +1156,12 @@ AT_SETUP([[Token number in precedence declaration]])
# POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
# we lost this in Bison 1.50.
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%{
#include <stdio.h>
void yyerror (char const *);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%error-verbose
@@ -1221,19 +1181,8 @@ sr_conflict:
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
int
yylex (void)
{
static int const input[] = { 1, 2, 3, 0 };
static int const *inputp = input;
return *inputp++;
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE([{ 1, 2, 3, 0 }])[
int
main (void)
@@ -1241,6 +1190,7 @@ main (void)
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
[[input.y:23.5-19: warning: rule useless in parser due to conflicts: start: start
@@ -1283,11 +1233,12 @@ AT_CLEANUP
AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>
void yyerror (char const *);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
#define YYSTACK_USE_ALLOCA 1
}
@@ -1323,28 +1274,18 @@ syntax_error:
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
int
yylex (void)
{
/* Induce two syntax error messages (which requires full error
recovery by shifting 3 tokens) in order to detect any loss of the
reallocated buffer. */
static char const *input = "abc";
return *input++;
}
]AT_YYERROR_DEFINE[
/* Induce two syntax error messages (which requires full error
recovery by shifting 3 tokens) in order to detect any loss of the
reallocated buffer. */
]AT_YYLEX_DEFINE(["abc"])[
int
main (void)
{
return yyparse ();
}
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([[-o input.c input.y]])
AT_COMPILE([[input]])
@@ -1370,12 +1311,12 @@ AT_CLEANUP
# yyparse would invoke yyerror using the old contents of yymsg.
AT_SETUP([[%error-verbose overflow]])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>
void yyerror (char const *);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
/* This prevents this test case from having to induce error messages
large enough to overflow size_t. */
@@ -1441,21 +1382,10 @@ syntax_error2:
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
int
yylex (void)
{
/* Induce two syntax error messages (which requires full error
recovery by shifting 3 tokens). */
static char const *input = "abc";
return *input++;
}
]AT_YYERROR_DEFINE[
/* Induce two syntax error messages (which requires full error
recovery by shifting 3 tokens). */
]AT_YYLEX_DEFINE(["abc"])[
int
main (void)
{
@@ -1481,7 +1411,7 @@ AT_PARSER_CHECK([[./input]], [[2]], [],
syntax error
memory exhausted
]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
@@ -1499,7 +1429,7 @@ AT_BISON_OPTION_PUSHDEFS([$1])
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>
void yyerror (char const *);
]AT_YYERROR_DECLARE[
int yylex (]AT_PURE_IF([[YYSTYPE *]], [[void]])[);
}
@@ -1520,13 +1450,7 @@ B: 'b' ;
C: /*empty*/ { printf ("consistent default reduction\n"); } ;
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
int
yylex (]AT_PURE_IF([[YYSTYPE *v]], [[void]])[)
{
@@ -1592,13 +1516,13 @@ AT_CLEANUP
AT_SETUP([[LAC: Memory exhaustion]])
m4_pushdef([AT_LAC_CHECK], [
m4_pushdef([AT_LAC_CHECK],
[AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <stdio.h>
void yyerror (char const *);
int yylex (void);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
#define YYMAXDEPTH 8
}
@@ -1610,20 +1534,8 @@ S: A A A A A A A A A ;
A: /*empty*/ | 'a' ;
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
int
yylex (void)
{
static char const *input = "]$1[";
return *input++;
}
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["$1"])[
int
main (void)
{
@@ -1637,12 +1549,12 @@ AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
[[input.y: conflicts: 8 shift/reduce
]])
AT_COMPILE([[input]])
AT_BISON_OPTION_POPDEFS
])
# Check for memory exhaustion during parsing.
AT_LAC_CHECK([[]])
AT_PARSER_CHECK([[./input]], [[2]], [[]],
AT_LAC_CHECK([])
AT_PARSER_CHECK([[./input]], [[2]], [],
[[Starting parse
Entering state 0
Reading a token: Now at end of input.
@@ -1655,8 +1567,8 @@ Stack now 0
# Induce an immediate syntax error with an undefined token, and check
# for memory exhaustion while building syntax error message.
AT_LAC_CHECK([[z]], [[0]])
AT_PARSER_CHECK([[./input]], [[2]], [[]],
AT_LAC_CHECK([z], [[0]])
AT_PARSER_CHECK([[./input]], [[2]], [],
[[Starting parse
Entering state 0
Reading a token: Next token is token $undefined ()
+4 -7
View File
@@ -83,10 +83,11 @@ AT_CLEANUP
AT_SETUP([[Installed skeleton file names]])
AT_BISON_OPTION_PUSHDEFS
m4_pushdef([AT_GRAM],
[[%{
#include <stdio.h>
void yyerror (char const *msg);
]AT_YYERROR_DECLARE[
int yylex (void);
%}
@@ -99,12 +100,7 @@ start: ;
%%
void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
int
yylex (void)
{
@@ -139,6 +135,7 @@ AT_PARSER_CHECK([[./input-gram]], [[1]], [],
m4_popdef([AT_GRAM])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
+15 -11
View File
@@ -68,7 +68,7 @@ AT_CHECK([[sed -e '/^distcc\[[0-9]*\] /d' \
# to issue ERROR-MSG.
m4_define([AT_TEST_SYNCLINE],
[AT_SETUP([$1])
AT_BISON_OPTION_PUSHDEFS
# It seems impossible to find a generic scheme to check the location
# of an error. Even requiring GCC is not sufficient, since for instance
# the version modified by Apple:
@@ -98,6 +98,7 @@ AT_DATA([[input.y]], [$2])
AT_BISON_CHECK([-o input.c input.y])
AT_SYNCLINES_COMPILE([input.c])
AT_CHECK([cat stdout], 0, [$3])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
])
@@ -110,11 +111,12 @@ AT_CLEANUP
AT_TEST_SYNCLINE([Prologue synch line],
[[%{
#error "2"
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
%%
exp: '0';
%%
]],
[input.y:2: #error "2"
])
@@ -130,11 +132,12 @@ AT_TEST_SYNCLINE([%union synch line],
char dummy;
}
%{
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
%%
exp: '0';
%%
]],
[input.y:2: #error "2"
])
@@ -146,8 +149,8 @@ exp: '0';
AT_TEST_SYNCLINE([Postprologue synch line],
[[%{
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
%union
{
@@ -158,6 +161,7 @@ int yylex (void);
%}
%%
exp: '0';
%%
]],
[input.y:10: #error "10"
])
@@ -169,8 +173,8 @@ exp: '0';
AT_TEST_SYNCLINE([Action synch line],
[[%{
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
%%
exp:
@@ -188,8 +192,8 @@ exp:
AT_TEST_SYNCLINE([Epilogue synch line],
[[%{
void yyerror (const char *s);
int yylex (void);
]AT_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[
%}
%%
exp: '0';
+47 -62
View File
@@ -42,7 +42,8 @@ esac])
# Create FILE-NAME, containing a self checking parser for a huge
# triangular grammar.
m4_define([AT_DATA_TRIANGULAR_GRAMMAR],
[AT_DATA([[gengram.pl]],
[AT_BISON_OPTION_PUSHDEFS
AT_DATA([[gengram.pl]],
[[#! /usr/bin/perl -w
use strict;
@@ -55,9 +56,10 @@ print <<EOF;
%{
#include <stdio.h>
#include <stdlib.h>
static int yylex (void);
static void yyerror (const char *msg);
#include <assert.h>
#define MAX $max
]AT_YYLEX_DECLARE[
]AT_YYERROR_DECLARE[
%}
%union
{
@@ -76,8 +78,8 @@ for my $size (1 .. $max)
print <<EOF;
%%
input:
exp { if (\@S|@1 != 0) abort (); \$\$ = \@S|@1; }
| input exp { if (\@S|@2 != \@S|@1 + 1) abort (); \$\$ = \@S|@2; }
exp { assert (\@S|@1 == 0); \$\$ = \@S|@1; }
| input exp { assert (\@S|@2 == \@S|@1 + 1); \$\$ = \@S|@2; }
;
exp:
@@ -95,14 +97,15 @@ for my $size (1 .. $max)
};
print ";\n";
print <<EOF;
print <<\EOF;
%%
]AT_YYERROR_DEFINE[
static int
yylex (void)
{
static int inner = 1;
static int outer = 0;
if (outer > $max)
if (outer > MAX)
return 0;
else if (inner > outer)
{
@@ -112,13 +115,6 @@ yylex (void)
}
return inner++;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\\n", msg);
}
int
main (void)
{
@@ -127,6 +123,7 @@ main (void)
}
EOF
]])
AT_BISON_OPTION_POPDEFS
AT_CHECK([perl -w ./gengram.pl $2 || exit 77], 0, [stdout])
mv stdout $1
@@ -157,7 +154,8 @@ AT_CLEANUP
# Create FILE-NAME, containing a self checking parser for a huge
# horizontal grammar.
m4_define([AT_DATA_HORIZONTAL_GRAMMAR],
[AT_DATA([[gengram.pl]],
[AT_BISON_OPTION_PUSHDEFS
AT_DATA([[gengram.pl]],
[[#! /usr/bin/perl -w
use strict;
@@ -170,9 +168,9 @@ print <<EOF;
%{
#include <stdio.h>
#include <stdlib.h>
static int yylex (void);
static void yyerror (const char *msg);
#define MAX $max
]AT_YYLEX_DECLARE[
]AT_YYERROR_DECLARE[
%}
%token
@@ -193,25 +191,20 @@ print
(map { "\"$_\"" } (1 .. $max)), ";"),
"\n";
print <<EOF;
print <<\EOF;
%%
#include <assert.h>
]AT_YYERROR_DEFINE[
static int
yylex (void)
{
static int counter = 1;
if (counter <= $max)
if (counter <= MAX)
return counter++;
if (counter++ != $max + 1)
abort ();
assert (counter++ == MAX + 1);
return 0;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\\n", msg);
}
int
main (void)
{
@@ -223,6 +216,7 @@ EOF
AT_CHECK([perl -w ./gengram.pl $2 || exit 77], 0, [stdout])
mv stdout $1
AT_BISON_OPTION_POPDEFS
])
@@ -263,7 +257,8 @@ AT_CLEANUP
# Create FILE-NAME, containing a self checking parser for a grammar
# requiring SIZE lookahead tokens.
m4_define([AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR],
[AT_DATA([[gengram.pl]],
[AT_BISON_OPTION_PUSHDEFS
AT_DATA([[gengram.pl]],
[[#! /usr/bin/perl -w
use strict;
@@ -277,9 +272,9 @@ print <<EOF;
# include <stdio.h>
# include <stdlib.h>
# include <assert.h>
static int yylex (void);
static void yyerror (const char *msg);
# define MAX $max
]AT_YYLEX_DECLARE[
]AT_YYERROR_DECLARE[
%}
%union
{
@@ -324,17 +319,17 @@ for my $count (1 .. $max)
print "n$count: token { \$\$ = $count; };\n";
};
print <<EOF;
print <<\EOF;
%%
]AT_YYERROR_DEFINE[
static int
yylex (void)
{
static int return_token = 1;
static int counter = 1;
if (counter > $max)
if (counter > MAX)
{
if (counter++ != $max + 1)
abort ();
assert (counter++ == MAX + 1);
return 0;
}
if (return_token)
@@ -346,12 +341,6 @@ yylex (void)
return counter++;
}
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\\n", msg);
}
int
main (void)
{
@@ -363,6 +352,7 @@ EOF
AT_CHECK([perl -w ./gengram.pl $2 || exit 77], 0, [stdout])
mv stdout $1
AT_BISON_OPTION_POPDEFS
])
@@ -390,7 +380,8 @@ AT_CLEANUP
# ------------------------------------------------
# A parser specialized in torturing the stack size.
m4_define([AT_DATA_STACK_TORTURE],
[# A grammar of parens growing the stack thanks to right recursion.
[AT_BISON_OPTION_PUSHDEFS([$2])
# A grammar of parens growing the stack thanks to right recursion.
# exp:
AT_DATA([input.y],
[[%{
@@ -399,8 +390,8 @@ AT_DATA([input.y],
#include <stdio.h>
#include <stdlib.h>
]$1[
static int yylex (void);
static void yyerror (const char *msg);
]AT_YYLEX_DECLARE[
]AT_YYERROR_DECLARE[
%}
]$2[
%error-verbose
@@ -409,17 +400,12 @@ AT_DATA([input.y],
%%
exp: WAIT_FOR_EOF exp | ;
%%
static void
yyerror (const char *msg)
{
fprintf (stderr, "%s\n", msg);
}
]AT_YYERROR_DEFINE[
#include <assert.h>
static int
yylex (void)
{
if (yylval < 0)
abort ();
assert (0 <= yylval);
if (yylval--)
return WAIT_FOR_EOF;
else
@@ -431,13 +417,12 @@ main (int argc, const char **argv)
{
char *endp;
YYSTYPE yylval_init;
if (argc != 2)
abort ();
assert (argc == 2);
yylval_init = strtol (argv[1], &endp, 10);
if (! (argv[1] != endp
&& 0 <= yylval_init && yylval_init <= INT_MAX
&& errno != ERANGE))
abort ();
assert (argv[1] != endp);
assert (0 <= yylval_init);
assert (yylval_init <= INT_MAX);
assert (errno != ERANGE);
yydebug = 1;
{
int count;
@@ -452,8 +437,7 @@ main (int argc, const char **argv)
[[ new_status = yypull_parse (ps);
]],
[[ new_status = yyparse ();
]])[ if (count > 0 && new_status != status)
abort ();
]])[ assert (0 <= count || new_status == status);
status = new_status;
}
]m4_bmatch([$2], [%push-],
@@ -462,6 +446,7 @@ main (int argc, const char **argv)
}
}
]])
AT_BISON_OPTION_POPDEFS([$2])
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input])
])