]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
Clean up handling of %destructor for the end token (token 0).
[bison.git] / data / lalr1.cc
index 8affc736095c4caa4c6a3feb14b466788761b890..377659e54100c6e56174310dad31b4742b317933 100644 (file)
@@ -20,6 +20,11 @@ m4_divert(-1)
 # 02110-1301  USA
 
 m4_include(b4_pkgdatadir/[c++.m4])
 # 02110-1301  USA
 
 m4_include(b4_pkgdatadir/[c++.m4])
+
+# The header is mandatory.
+b4_defines_if([],
+              [m4_fatal(b4_skeleton[: using %defines is mandatory])])
+
 # Backward compatibility.
 m4_define([b4_location_constructors])
 m4_include(b4_pkgdatadir/[location.cc])
 # Backward compatibility.
 m4_define([b4_location_constructors])
 m4_include(b4_pkgdatadir/[location.cc])
@@ -27,25 +32,12 @@ m4_include(b4_pkgdatadir/[location.cc])
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
 m4_divert(0)dnl
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
 m4_divert(0)dnl
-m4_if(b4_defines_flag, 0, [],
+b4_defines_if(
 [@output @output_header_name@
 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
   [2002, 2003, 2004, 2005, 2006])
 dnl FIXME: This is wrong, we want computed header guards.
 [
 [@output @output_header_name@
 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
   [2002, 2003, 2004, 2005, 2006])
 dnl FIXME: This is wrong, we want computed header guards.
 [
-/* As a special exception, you may create a larger work that contains
-   part or all of the Bison parser skeleton and distribute that work
-   under terms of your choice, so long as that work isn't itself a
-   parser generator using the skeleton or a modified version thereof
-   as a parser skeleton.  Alternatively, if you modify or redistribute
-   the parser skeleton itself, you may (at your option) remove this
-   special exception, which will cause the skeleton and the resulting
-   Bison output files to be licensed under the GNU General Public
-   License without this special exception.
-
-   This special exception was added by the Free Software Foundation in
-   version 2.2 of Bison.  */
-
 /* C++ LALR(1) parser skeleton written by Akim Demaille.  */
 
 #ifndef PARSER_HEADER_H
 /* C++ LALR(1) parser skeleton written by Akim Demaille.  */
 
 #ifndef PARSER_HEADER_H
@@ -61,18 +53,16 @@ namespace ]b4_namespace[
   class location;
 }
 
   class location;
 }
 
-/* First part of user declarations.  */
-]b4_pre_prologue[
-
-]/* Line __line__ of lalr1.cc.  */
-b4_syncline([@oline@], [@ofile@])[
+]m4_ifdef([b4_start_header],
+[[/* Copy the %start-header blocks.  */
+]b4_user_start_header])[
 
 ]dnl Include location.hh here: it might depend on headers included above.
 [#include "location.hh"
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
 
 ]dnl Include location.hh here: it might depend on headers included above.
 [#include "location.hh"
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
-# define YYDEBUG ]b4_debug[
+# define YYDEBUG ]b4_debug_flag[
 #endif
 
 /* Enabling verbose error messages.  */
 #endif
 
 /* Enabling verbose error messages.  */
@@ -80,7 +70,7 @@ b4_syncline([@oline@], [@ofile@])[
 # undef YYERROR_VERBOSE
 # define YYERROR_VERBOSE 1
 #else
 # undef YYERROR_VERBOSE
 # define YYERROR_VERBOSE 1
 #else
-# define YYERROR_VERBOSE ]b4_error_verbose[
+# define YYERROR_VERBOSE ]b4_error_verbose_flag[
 #endif
 
 /* Enabling the token table.  */
 #endif
 
 /* Enabling the token table.  */
@@ -118,11 +108,11 @@ namespace ]b4_namespace[
 #ifndef YYSTYPE
 ]m4_ifdef([b4_stype],
 [    union semantic_type
 #ifndef YYSTYPE
 ]m4_ifdef([b4_stype],
 [    union semantic_type
-b4_stype
-/* Line __line__ of lalr1.cc.  */
-b4_syncline([@oline@], [@ofile@])
+b4_user_stype
        ;],
        ;],
-[    typedef int semantic_type;])[
+[m4_if(b4_tag_seen_flag, 0,
+[[    typedef int semantic_type;]],
+[[    typedef YYSTYPE semantic_type;]])])[
 #else
     typedef YYSTYPE semantic_type;
 #endif
 #else
     typedef YYSTYPE semantic_type;
 #endif
@@ -164,7 +154,7 @@ b4_syncline([@oline@], [@ofile@])
 
     /// Generate an error message.
     /// \param state   the state where the error occurred.
 
     /// Generate an error message.
     /// \param state   the state where the error occurred.
-    /// \param tok     the look-ahead token.
+    /// \param tok     the lookahead token.
     virtual std::string yysyntax_error_ (int yystate]dnl
 b4_error_verbose_if([, int tok])[);
 
     virtual std::string yysyntax_error_ (int yystate]dnl
 b4_error_verbose_if([, int tok])[);
 
@@ -306,39 +296,29 @@ b4_error_verbose_if([, int tok])[);
  /* Redirection for backward compatibility.  */
 # define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
 #endif
  /* Redirection for backward compatibility.  */
 # define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
 #endif
-])[
-#endif /* ! defined PARSER_HEADER_H */]
+])
+m4_ifdef([b4_end_header],
+[[/* Copy the %end-header blocks.  */
+]b4_end_header])[]dnl
+
+[#endif /* ! defined PARSER_HEADER_H */]
 ])dnl
 @output @output_parser_name@
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
   [2002, 2003, 2004, 2005, 2006])
 ])dnl
 @output @output_parser_name@
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
   [2002, 2003, 2004, 2005, 2006])
-[
-/* As a special exception, you may create a larger work that contains
-   part or all of the Bison parser skeleton and distribute that work
-   under terms of your choice, so long as that work isn't itself a
-   parser generator using the skeleton or a modified version thereof
-   as a parser skeleton.  Alternatively, if you modify or redistribute
-   the parser skeleton itself, you may (at your option) remove this
-   special exception, which will cause the skeleton and the resulting
-   Bison output files to be licensed under the GNU General Public
-   License without this special exception.
-
-   This special exception was added by the Free Software Foundation in
-   version 2.2 of Bison.  */
-]
 m4_if(b4_prefix, [yy], [],
 [
 // Take the name prefix into account.
 m4_if(b4_prefix, [yy], [],
 [
 // Take the name prefix into account.
-#define yylex   b4_prefix[]lex])
-m4_if(b4_defines_flag, 0, [],
-[
+#define yylex   b4_prefix[]lex])[
+
+/* First part of user declarations.  */
+]b4_pre_prologue
+
+b4_defines_if([
 #include @output_header_name@])[
 
 /* User implementation prologue.  */
 #include @output_header_name@])[
 
 /* User implementation prologue.  */
-]b4_post_prologue[
-
-]/* Line __line__ of lalr1.cc.  */
-b4_syncline([@oline@], [@ofile@])[
+]b4_user_post_prologue[
 
 #ifndef YY_
 # if YYENABLE_NLS
 
 #ifndef YY_
 # if YYENABLE_NLS
@@ -356,9 +336,7 @@ b4_syncline([@oline@], [@ofile@])[
 #define YYUSE(e) ((void) (e))
 
 /* A pseudo ostream that takes yydebug_ into account.  */
 #define YYUSE(e) ((void) (e))
 
 /* A pseudo ostream that takes yydebug_ into account.  */
-# define YYCDEBUG                                                      \
-  for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false)       \
-    (*yycdebug_)
+# define YYCDEBUG if (yydebug_) (*yycdebug_)
 
 /* Enable debugging if requested.  */
 #if YYDEBUG
 
 /* Enable debugging if requested.  */
 #if YYDEBUG
@@ -538,7 +516,7 @@ namespace ]b4_namespace[
   int
   ]b4_parser_class_name[::parse ()
   {
   int
   ]b4_parser_class_name[::parse ()
   {
-    /// Look-ahead and look-ahead in internal form.
+    /// Lookahead and lookahead in internal form.
     int yychar = yyempty_;
     int yytoken = 0;
 
     int yychar = yyempty_;
     int yytoken = 0;
 
@@ -551,9 +529,9 @@ namespace ]b4_namespace[
     int yynerrs_ = 0;
     int yyerrstatus_ = 0;
 
     int yynerrs_ = 0;
     int yyerrstatus_ = 0;
 
-    /// Semantic value of the look-ahead.
+    /// Semantic value of the lookahead.
     semantic_type yylval;
     semantic_type yylval;
-    /// Location of the look-ahead.
+    /// Location of the lookahead.
     location_type yylloc;
     /// The locations where the error started and ended.
     location yyerror_range[2];
     location_type yylloc;
     /// The locations where the error started and ended.
     location yyerror_range[2];
@@ -571,11 +549,9 @@ namespace ]b4_namespace[
 m4_pushdef([b4_at_dollar],     [yylloc])dnl
 m4_pushdef([b4_dollar_dollar], [yylval])dnl
     /* User initialization code.  */
 m4_pushdef([b4_at_dollar],     [yylloc])dnl
 m4_pushdef([b4_dollar_dollar], [yylval])dnl
     /* User initialization code.  */
-    b4_initial_action
+    b4_user_initial_action
 m4_popdef([b4_dollar_dollar])dnl
 m4_popdef([b4_dollar_dollar])dnl
-m4_popdef([b4_at_dollar])dnl
-  /* Line __line__ of yacc.c.  */
-b4_syncline([@oline@], [@ofile@])])dnl
+m4_popdef([b4_at_dollar])])dnl
 
   [  /* Initialize the stacks.  The initial state will be pushed in
        yynewstate, since the latter expects the semantical and the
 
   [  /* Initialize the stacks.  The initial state will be pushed in
        yynewstate, since the latter expects the semantical and the
@@ -591,23 +567,28 @@ b4_syncline([@oline@], [@ofile@])])dnl
   yynewstate:
     yystate_stack_.push (yystate);
     YYCDEBUG << "Entering state " << yystate << std::endl;
   yynewstate:
     yystate_stack_.push (yystate);
     YYCDEBUG << "Entering state " << yystate << std::endl;
+
+    /* Accept?  */
+    if (yystate == yyfinal_)
+      goto yyacceptlab;
+
     goto yybackup;
 
     /* Backup.  */
   yybackup:
 
     goto yybackup;
 
     /* Backup.  */
   yybackup:
 
-    /* Try to take a decision without look-ahead.  */
+    /* Try to take a decision without lookahead.  */
     yyn = yypact_[yystate];
     if (yyn == yypact_ninf_)
       goto yydefault;
 
     yyn = yypact_[yystate];
     if (yyn == yypact_ninf_)
       goto yydefault;
 
-    /* Read a look-ahead token.  */
+    /* Read a lookahead token.  */
     if (yychar == yyempty_)
       {
        YYCDEBUG << "Reading a token: ";
        yychar = ]b4_c_function_call([yylex], [int],
                                     [[YYSTYPE*], [&yylval]][]dnl
     if (yychar == yyempty_)
       {
        YYCDEBUG << "Reading a token: ";
        yychar = ]b4_c_function_call([yylex], [int],
                                     [[YYSTYPE*], [&yylval]][]dnl
-b4_location_if([, [[location*], [&yylloc]]])dnl
+b4_locations_if([, [[location*], [&yylloc]]])dnl
 m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
       }
 
 m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
       }
 
@@ -640,16 +621,11 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
        goto yyreduce;
       }
 
        goto yyreduce;
       }
 
-    /* Accept?  */
-    if (yyn == yyfinal_)
-      goto yyacceptlab;
-
-    /* Shift the look-ahead token.  */
+    /* Shift the lookahead token.  */
     YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
 
     YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
 
-    /* Discard the token being shifted unless it is eof.  */
-    if (yychar != yyeof_)
-      yychar = yyempty_;
+    /* Discard the token being shifted.  */
+    yychar = yyempty_;
 
     yysemantic_stack_.push (yylval);
     yylocation_stack_.push (yylloc);
 
     yysemantic_stack_.push (yylval);
     yylocation_stack_.push (yylloc);
@@ -694,9 +670,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
     YY_REDUCE_PRINT (yyn);
     switch (yyn)
       {
     YY_REDUCE_PRINT (yyn);
     switch (yyn)
       {
-       ]b4_actions
-    /* Line __line__ of lalr1.cc.  */
-b4_syncline([@oline@], [@ofile@])[
+       ]b4_user_actions[
        default: break;
       }
     YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
        default: break;
       }
     YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
@@ -733,7 +707,7 @@ b4_error_verbose_if([, yytoken])[));
     yyerror_range[0] = yylloc;
     if (yyerrstatus_ == 3)
       {
     yyerror_range[0] = yylloc;
     if (yyerrstatus_ == 3)
       {
-       /* If just tried and failed to reuse look-ahead token after an
+       /* If just tried and failed to reuse lookahead token after an
         error, discard it.  */
 
        if (yychar <= yyeof_)
         error, discard it.  */
 
        if (yychar <= yyeof_)
@@ -749,7 +723,7 @@ b4_error_verbose_if([, yytoken])[));
          }
       }
 
          }
       }
 
-    /* Else will try to reuse look-ahead token after shifting the error
+    /* Else will try to reuse lookahead token after shifting the error
        token.  */
     goto yyerrlab1;
 
        token.  */
     goto yyerrlab1;
 
@@ -806,12 +780,9 @@ b4_error_verbose_if([, yytoken])[));
        YY_STACK_PRINT ();
       }
 
        YY_STACK_PRINT ();
       }
 
-    if (yyn == yyfinal_)
-      goto yyacceptlab;
-
     yyerror_range[1] = yylloc;
     // Using YYLLOC is tempting, but would change the location of
     yyerror_range[1] = yylloc;
     // Using YYLLOC is tempting, but would change the location of
-    // the look-ahead.  YYLOC is available though.
+    // the lookahead.  YYLOC is available though.
     YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
     yysemantic_stack_.push (yylval);
     yylocation_stack_.push (yyloc);
     YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
     yysemantic_stack_.push (yylval);
     yylocation_stack_.push (yyloc);
@@ -834,7 +805,7 @@ b4_error_verbose_if([, yytoken])[));
     goto yyreturn;
 
   yyreturn:
     goto yyreturn;
 
   yyreturn:
-    if (yychar != yyeof_ && yychar != yyempty_)
+    if (yychar != yyempty_)
       yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
 
     /* Do not reclaim the symbols of the rule which action triggered
       yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
 
     /* Do not reclaim the symbols of the rule which action triggered
@@ -861,14 +832,14 @@ b4_error_verbose_if([, int tok])[)
     YYUSE (yystate);
 #if YYERROR_VERBOSE
     int yyn = yypact_[yystate];
     YYUSE (yystate);
 #if YYERROR_VERBOSE
     int yyn = yypact_[yystate];
-    if (yypact_ninf_ < yyn && yyn < yylast_)
+    if (yypact_ninf_ < yyn && yyn <= yylast_)
       {
        /* Start YYX at -YYN if negative to avoid negative indexes in
           YYCHECK.  */
        int yyxbegin = yyn < 0 ? -yyn : 0;
 
        /* Stay within bounds of both yycheck and yytname.  */
       {
        /* Start YYX at -YYN if negative to avoid negative indexes in
           YYCHECK.  */
        int yyxbegin = yyn < 0 ? -yyn : 0;
 
        /* Stay within bounds of both yycheck and yytname.  */
-       int yychecklim = yylast_ - yyn;
+       int yychecklim = yylast_ - yyn + 1;
        int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
        int count = 0;
        for (int x = yyxbegin; x < yyxend; ++x)
        int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
        int count = 0;
        for (int x = yyxbegin; x < yyxend; ++x)
@@ -1080,20 +1051,7 @@ b4_error_verbose_if([, int tok])[)
 dnl
 @output b4_dir_prefix[]stack.hh
 b4_copyright([Stack handling for Bison parsers in C++],
 dnl
 @output b4_dir_prefix[]stack.hh
 b4_copyright([Stack handling for Bison parsers in C++],
-  [2002, 2003, 2004, 2005, 2006])
-[
-/* As a special exception, you may create a larger work that contains
-   part or all of the Bison parser skeleton and distribute that work
-   under terms of your choice, so long as that work isn't itself a
-   parser generator using the skeleton or a modified version thereof
-   as a parser skeleton.  Alternatively, if you modify or redistribute
-   the parser skeleton itself, you may (at your option) remove this
-   special exception, which will cause the skeleton and the resulting
-   Bison output files to be licensed under the GNU General Public
-   License without this special exception.
-
-   This special exception was added by the Free Software Foundation in
-   version 2.2 of Bison.  */
+  [2002, 2003, 2004, 2005, 2006])[
 
 #ifndef BISON_STACK_HH
 # define BISON_STACK_HH
 
 #ifndef BISON_STACK_HH
 # define BISON_STACK_HH