]> git.saurik.com Git - bison.git/commitdiff
Merge remote-tracking branch 'origin/maint'
authorAkim Demaille <akim@lrde.epita.fr>
Tue, 19 Jun 2012 15:35:53 +0000 (17:35 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Tue, 19 Jun 2012 16:17:09 +0000 (18:17 +0200)
* origin/maint:
  maint: formatting changes.
  tests: support api.prefix.
  tests: pacify font-lock-mode.
  tests: remove test covered elsewhere.
  tests: factor the declaration/definition of yyerror and yylex.
  regen.
  tests: portability issues.
  tests: call the parser from another compilation unit.
  glr.c, yacc.c: declare yydebug in the header.
  skeletons: use header guards.
  tests: improve AT_FULL_COMPILE.
  tests: reorder.
  tests: strengthen the test on generated headers inclusion
  yacc.c: instead of duplicating y.tab.h inside y.tac.c, include it.
  yacc.c: factor.

Conflicts:
NEWS
data/glr.c
data/yacc.c
src/parse-gram.c
src/parse-gram.h
tests/conflicts.at
tests/regression.at

14 files changed:
1  2 
NEWS
data/c.m4
data/glr.c
data/glr.cc
data/yacc.c
tests/actions.at
tests/calc.at
tests/conflicts.at
tests/glr-regression.at
tests/input.at
tests/local.at
tests/named-refs.at
tests/regression.at
tests/torture.at

diff --cc NEWS
index 79fdb8ef5418cab9c0ecf2278c4866944dc256dd,9c5d67b7e52fa246e9593fde2a6b4a95a10c2580..7b75972c4ace5457e59ee46acdc29c20c208ab9e
--- 1/NEWS
--- 2/NEWS
+++ b/NEWS
@@@ -2,72 -2,45 +2,113 @@@ GNU Bison NEW
  
  * Noteworthy changes in release ?.? (????-??-??) [?]
  
-       %lex-param   {arg1_type *arg1}
-       %lex-param   {arg2_type *arg2}
-       %parse-param {arg1_type *arg1}
-       %parse-param {arg2_type *arg2}
 +** Additional yylex/yyparse arguments
 +
 +  The new directive %param declare additional argument to both yylex
 +  and yyparse.  The %lex-param, %parse-param, and %param directives
 +  support one or more arguments.  Instead of
 +
-       %param {arg1_type *arg1} {arg2_type *arg2}
++    %lex-param   {arg1_type *arg1}
++    %lex-param   {arg2_type *arg2}
++    %parse-param {arg1_type *arg1}
++    %parse-param {arg2_type *arg2}
 +
 +  one may now declare
 +
-       %token FILE for ERROR
-       %define api.tokens.prefix "TOK_"
-       %%
-       start: FILE for ERROR;
++    %param {arg1_type *arg1} {arg2_type *arg2}
 +
 +** Java skeleton improvements
 +
 +  The constants for token names were moved to the Lexer interface.
 +  Also, it is possible to add code to the parser's constructors using
 +  "%code init" and "%define init_throws".
 +
 +** C++ skeleton improvements
 +
 +  The C++ parser features a syntax_error exception, which can be
 +  thrown from the scanner or from user rules to raise syntax errors.
 +  This facilitates reporting errors caught in sub-functions (e.g.,
 +  rejecting too large integral literals from a conversion function
 +  used by the scanner, or rejecting invalid combinations from a
 +  factory invoked by the user actions).
 +
 +** Variable api.tokens.prefix
 +
 +  The variable api.tokens.prefix changes the way tokens are identified in
 +  the generated files.  This is especially useful to avoid collisions
 +  with identifiers in the target language.  For instance
 +
++    %token FILE for ERROR
++    %define api.tokens.prefix "TOK_"
++    %%
++    start: FILE for ERROR;
 +
 +  will generate the definition of the symbols TOK_FILE, TOK_for, and
 +  TOK_ERROR in the generated sources.  In particular, the scanner must
 +  use these prefixed token names, although the grammar itself still
 +  uses the short names (as in the sample rule given above).
 +
 +** Variable api.namespace
 +
 +  The "namespace" variable is renamed "api.namespace".  Backward
 +  compatibility is ensured, but upgrading is recommended.
 +
 +** Variable parse.error
 +
 +  The variable error controls the verbosity of error messages.  The
 +  use of the %error-verbose directive is deprecated in favor of
 +  %define parse.error "verbose".
 +
 +** Semantic predicates
 +
 +  The new, experimental, semantic-predicate feature allows actions of
 +  the form %?{ BOOLEAN-EXPRESSION }, which cause syntax errors (as for
 +  YYERROR) if the expression evaluates to 0, and are evaluated immediately
 +  in GLR parsers, rather than being deferred.  The result is that they
 +  allow the programmer to prune possible parses based on the values of
 +  runtime expressions.
 +
++* Noteworthy changes in release ?.? (????-??-??) [?]
++
+ ** Future changes:
+   The next major release will drop support for generating parsers in K&R C,
+   and remove the definition of yystype (removal announced since Bison
+   1.875).
+ ** The generated header is included (yacc.c)
+   Instead of duplicating the content of the generated header (definition of
+   YYSTYPE, yyltype etc.), the generated parser now includes it, as was
+   already the case for GLR or C++ parsers.
+ ** Headers (yacc.c, glr.c, glr.cc)
+ *** Guards
+   The generated headers are now guarded, as is already the case for C++
+   parsers (lalr1.cc).  For intance, with --defines=foo.h:
+     #ifndef YY_FOO_H
+     # define YY_FOO_H
+     ...
+     #endif /* !YY_FOO_H  */
+ *** New declarations
+   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.
  * Noteworthy changes in release 2.5.1 (2012-06-05) [stable]
  
  ** Future changes:
diff --cc data/c.m4
index 2b7e9d63c9523372a5a78807e56eb1ec36db8f7c,78b123252833690f0df1d8aa44611ec32e8deb07..2601d561945d0b6adc35c888da540742f9a1ea5f
+++ b/data/c.m4
@@@ -604,3 -567,15 +604,15 @@@ typedef struct YYLTYP
  # define YYLTYPE_IS_TRIVIAL 1
  #endif]])
  ])
 -# define YYDEBUG ]b4_debug_flag[
+ # b4_declare_yydebug
+ # ------------------
+ m4_define([b4_declare_yydebug],
+ [[/* Enabling traces.  */
+ #ifndef YYDEBUG
++# define YYDEBUG ]b4_parse_trace_if([1], [0])[
+ #endif
+ #if YYDEBUG
+ extern int ]b4_prefix[debug;
+ #endif][]dnl
+ ])
diff --cc data/glr.c
index 1463a9a7f6def1f343befbcd466b2dfe4ce4b9fa,9bbf9a72e936aae0092fc18bf0598f792adc11c3..f4efca2c02a4379bd40484c944ce21b5f4219c19
@@@ -211,13 -205,8 +213,8 @@@ m4_if(b4_prefix, [yy], []
  ]b4_null_define[
  
  ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
 -               [b4_shared_declarations])[
 +              [b4_shared_declarations])[
  
- /* Enabling traces.  */
- #ifndef YYDEBUG
- # define YYDEBUG ]b4_parse_trace_if([1], [0])[
- #endif
  /* Enabling verbose error messages.  */
  #ifdef YYERROR_VERBOSE
  # undef YYERROR_VERBOSE
@@@ -416,10 -455,20 +413,7 @@@ dnl We probably ought to introduce a ty
  {
    ]b4_conflicting_rules[
  };
 -
 -static const ]b4_int_type_for([b4_check])[ yycheck[] =
 -{
 -  ]b4_check[
 -};
 -
 -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
 -   symbol of state STATE-NUM.  */
 -static const ]b4_int_type_for([b4_stos])[ yystos[] =
 -{
 -  ]b4_stos[
 -};
 -
  \f
- /* Prevent warning if -Wmissing-prototypes.  */
- ]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
  /* Error token number */
  #define YYTERROR 1
  
diff --cc data/glr.cc
Simple merge
diff --cc data/yacc.c
index 922a4ebec9d1b365fcd39b07dd8de461ebefb247,30c5f672aff3a5f3ee959b5f3bfeeccab33617a3..56be747aecf8a8650cabccda43748af0789b2da1
@@@ -1973,40 -2058,17 +1992,16 @@@ yypushreturn:]])
    return YYID (yyresult);
  }
  
 -
 -]b4_epilogue
 +]b4_epilogue[]dnl
  b4_defines_if(
  [@output(b4_spec_defines_file@)@
- b4_copyright([Bison interface for Yacc-like parsers in C])dnl
- b4_percent_code_get([[requires]])[]dnl
 -b4_copyright([Bison interface for Yacc-like parsers in C],
 -             [1984, 1989-1990, 2000-2012])[
++b4_copyright([Bison interface for Yacc-like parsers in C])[
  
b4_token_enums_defines(b4_tokens)[
- ]b4_declare_yylstype[
]b4_cpp_guard_open([b4_spec_defines_file])[
+ ]b4_shared_declarations[
  ]b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval;
- ]b4_locations_if([[extern YYLTYPE ]b4_prefix[lloc;]])])dnl
- 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_locations_if([[extern YYLTYPE ]b4_prefix[lloc;]])])[
+ ]b4_cpp_guard_close([b4_spec_defines_file])[
+ ]])dnl b4_defines_if
  m4_divert_pop(0)
 +m4_popdef([b4_copyright_years])
index 8be86f073476755736f605e439eba20de98e8481,cfac299202a9e204042ac419df3ab6cf303602b3..84529bef7672dd630fc1b68e65c393df64e4d8c8
@@@ -28,14 -28,13 +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
 +[[%define parse.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'); }
@@@ -92,14 -78,13 +78,13 @@@ AT_CLEANU
  
  AT_SETUP([Exotic Dollars])
  
+ AT_BISON_OPTION_PUSHDEFS
  AT_DATA_GRAMMAR([[input.y]],
 -[[%error-verbose
 +[[%define parse.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)
  %}
  
@@@ -164,9 -136,9 +136,9 @@@ AT_PARSER_CHECK([./input], 0
  AT_DATA_GRAMMAR([[input.y]],
  [[
  %{
 -#include <stdio.h>
 +# include <stdio.h>
-   static int yylex (void);
-   static void yyerror (char const *msg);
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
    typedef struct { int val; } stype;
  # define YYSTYPE stype
  %}
@@@ -632,9 -601,9 +601,9 @@@ AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-p
  # 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
 +[[%define parse.error verbose
  %debug
  %locations
  %initial-action {
@@@ -750,9 -703,9 +703,9 @@@ AT_CLEANU
  ## ------------------------------------------------------ ##
  
  AT_SETUP([Default tagged and per-type %printer and %destructor])
+ AT_BISON_OPTION_PUSHDEFS
  AT_DATA_GRAMMAR([[input.y]],
 -[[%error-verbose
 +[[%define parse.error verbose
  %debug
  
  %{
@@@ -895,8 -835,9 +835,9 @@@ m4_define([_AT_CHECK_DEFAULT_PRINTER_AN
    [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
 +[[%define parse.error verbose
  %debug
  %locations
  %initial-action {
diff --cc tests/calc.at
index 477c92d3759f5fe90bb5784c645498db6c796156,77f70cd3b4ebe2b33636a7e14ae54d794be69a5f..5c6c4cc11f539d17f370eaba459b0556643f1d92
@@@ -305,21 -379,11 +379,10 @@@ power (int base, int exponent
  
  /* A C++ error reporting function.  */
  void
 -AT_NAME_PREFIX::parser::error (const location_type& l, const std::string& m)
 +AT_NAME_PREFIX::parser::error (AT_LOCATION_IF([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 ();
- }
  ],
  [/* A C error reporting function.  */
  static void
Simple merge
Simple merge
diff --cc tests/input.at
index d0bc51a75aa06937570cf187ae1e24adb266ba0a,2f667d0ad5c6a6a3adf3b6a9751bb86bf48bcaf7..d94b652ec6cb36cf45b1596e3d087bbee66f4adf
@@@ -509,15 -514,9 +509,9 @@@ yylex (void
    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;
diff --cc tests/local.at
index a53f1d17adc4201c967024b6412426b72522e1e1,6d3ff18f9568b6091af13f4dc529d7d410a88b2b..0d24a44a3d0bf7242e9d230996eea3b69e5b96f2
@@@ -135,11 -135,12 +135,15 @@@ 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_bregexp([$3], [name-prefix "\([^""]*\)"], [\1])],
+            [yy])])
+ m4_pushdef([AT_API_PREFIX],
+ [m4_bmatch([$3], [%define api\.prefix ".*"],
+            [m4_bregexp([$3], [%define api\.prefix "\([^""]*\)"], [\1])],
             [yy])])
 +m4_pushdef([AT_TOKEN_PREFIX],
 +[m4_bmatch([$3], [%define api.tokens.prefix ".*"],
 +           [m4_bregexp([$3], [%define api.tokens.prefix "\(.*\)"], [\1])])])
  # 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])],
@@@ -464,16 -528,27 +533,27 @@@ AT_CHECK([[$SHELL ../../../javacomp.sh 
  # 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_BISON_CHECK([-o $1.java $1.y])
+     AT_JAVA_COMPILE([$1.java],
+                     m4_join([ ],
+                             [$1.java],
+                             m4_ifval($2, [[$1-$2.java]]),
+                             m4_ifval($3, [[$1-$3.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.cc $1.y])
+       AT_COMPILE_CXX([$1],
+                      m4_join([ ],
+                              [$1.cc],
+                              m4_ifval($2, [[$1-$2.cc]]),
+                              m4_ifval($3, [[$1-$3.cc]])))
      ], [
-       AT_BISON_CHECK([[-o ]$1[.c ]$1[.y]])
-       AT_COMPILE([$1]m4_ifval($2, [, [$1[.c ]$1[-]$2[.c]]]))
+       AT_BISON_CHECK([-o $1.c $1.y])
+       AT_COMPILE([$1],
+                   m4_join([ ],
 -                        [$1.c],
++                          [$1.c],
+                           m4_ifval($2, [[$1-$2.c]]),
+                           m4_ifval($3, [[$1-$3.c]])))
      ])
    ])
  ])
Simple merge
index ff798a87a85cd0190b154210f8733cc0f49d6ae9,fa93833cd0d08b3bf4378e8b54c4a5bfe79243cc..fd08800a28e5ae7ce0e76b03c310da171926c059
@@@ -825,10 -852,10 +843,10 @@@ m4_define([_AT_DATA_DANCER_Y]
  [AT_DATA_GRAMMAR([dancer.y],
  [%{
  static int yylex (AT_LALR1_CC_IF([int *], [void]));
 -AT_LALR1_CC_IF([],
 +AT_LALR1_CC_IF([#include <cstdlib>],
  [#include <stdlib.h>
  #include <stdio.h>
static void yyerror (const char *);])
]AT_YYERROR_DECLARE[])
  %}
  $1
  %token ARROW INVALID NUMBER STRING DATA
@@@ -951,12 -978,12 +969,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]));
 -AT_LALR1_CC_IF([],
 -[[#include <stdio.h>
 -#include <stdlib.h>
 +[%{
 +static int yylex (AT_LALR1_CC_IF([int *], [void]));
- AT_LALR1_CC_IF([#include <cstdlib>],
- [#include <stdio.h>
- #include <stdlib.h>
- static void yyerror (const char *);])
++AT_LALR1_CC_IF([[#include <cstdlib>]],
++[[#include <stdlib.h>
++#include <stdio.h>
+ ]AT_YYERROR_DECLARE])[
  %}
  $1
  %defines
@@@ -1269,12 -1276,13 +1268,13 @@@ AT_CLEANU
  
  
  
 -## --------------------------------------- ##
 -## %error-verbose and YYSTACK_USE_ALLOCA.  ##
 -## --------------------------------------- ##
 +## -------------------------------------------- ##
 +## parse.error=verbose and YYSTACK_USE_ALLOCA.  ##
 +## -------------------------------------------- ##
  
 -AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]])
 +AT_SETUP([[parse.error=verbose and YYSTACK_USE_ALLOCA]])
  
+ AT_BISON_OPTION_PUSHDEFS
  AT_DATA_GRAMMAR([input.y],
  [[%code {
    #include <stdio.h>
@@@ -1315,22 -1323,11 +1315,11 @@@ syntax_error
  
  %%
  
- void
- yyerror (char const *msg)
- {
-   fprintf (stderr, "%s\n", msg);
- }
- int
- yylex (void)
- {
+ ]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.  */
 +  /* 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_YYLEX_DEFINE([abc])[
  int
  main (void)
  {
@@@ -1361,8 -1359,8 +1351,9 @@@ AT_CLEANU
  # size calculation would return YYSIZE_MAXIMUM to yyparse.  Then,
  # yyparse would invoke yyerror using the old contents of yymsg.
  
 -AT_SETUP([[%error-verbose overflow]])
 +AT_SETUP([[parse.error=verbose overflow]])
 +
+ AT_BISON_OPTION_PUSHDEFS
  AT_DATA_GRAMMAR([input.y],
  [[%code {
    #include <stdio.h>
@@@ -1433,21 -1431,10 +1424,10 @@@ syntax_error2
  
  %%
  
- void
- yyerror (char const *msg)
- {
-   fprintf (stderr, "%s\n", msg);
- }
- int
- yylex (void)
- {
+ ]AT_YYERROR_DEFINE[
 -/* Induce two syntax error messages (which requires full error
 -   recovery by shifting 3 tokens).  */
 +  /* Induce two syntax error messages (which requires full error
 +     recovery by shifting 3 tokens).  */
-   static char const *input = "abc";
-   return *input++;
- }
+ ]AT_YYLEX_DEFINE([abc])[
  int
  main (void)
  {
Simple merge