]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
Merge remote-tracking branch 'origin/maint'
[bison.git] / data / lalr1.cc
index dab5ab9b05be425e69739d52ff984fd51f13d50b..92f93c2c75d6b98a9bdac4d4f10bd5d74a2f19cb 100644 (file)
@@ -1,6 +1,6 @@
 # C++ skeleton for Bison
 
-# Copyright (C) 2002-2011 Free Software Foundation, Inc.
+# Copyright (C) 2002-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
@@ -115,7 +115,7 @@ m4_popdef([b4_dollar_dollar])dnl
 
 
 m4_pushdef([b4_copyright_years],
-           [2002-2011])
+           [2002-2012])
 
 m4_define([b4_parser_class_name],
           [b4_percent_define_get([[parser_class_name]])])
@@ -126,8 +126,8 @@ b4_defines_if([],
 
 b4_locations_if([b4_percent_define_ifdef([[location_type]], [],
   [# Backward compatibility.
-  m4_define([b4_location_constructors])
-  m4_include(b4_pkgdatadir/[location.cc])])])
+   m4_define([b4_location_constructors])
+   m4_include(b4_pkgdatadir/[location.cc])])])
 m4_include(b4_pkgdatadir/[stack.hh])
 b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])])
 
@@ -136,12 +136,15 @@ m4_changecom()
 m4_divert_push(0)dnl
 @output(b4_spec_defines_file@)@
 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
-dnl FIXME: This is wrong, we want computed header guards.
 [
+/**
+ ** \file ]b4_spec_defines_file[
+ ** Define the ]b4_namespace_ref[::parser class.
+ */
+
 /* C++ LALR(1) 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]])[
 
@@ -157,6 +160,8 @@ dnl FIXME: This is wrong, we want computed header guards.
 b4_variant_define
 b4_namespace_close])[
 
+]b4_null_define[
+
 /* Enabling traces.  */
 #ifndef YYDEBUG
 # define YYDEBUG ]b4_parse_trace_if([1], [0])[
@@ -209,6 +214,9 @@ b4_namespace_close])[
     /// \param msg    a description of the syntax error.
     virtual void error (]b4_locations_if([const location_type& loc, ])[const std::string& msg);
 
+    /// Report a syntax error.
+    void error (const syntax_error& err);
+
   private:
     /// State numbers.
     typedef int state_type;
@@ -336,7 +344,7 @@ b4_namespace_close])[
       yyfinal_ = ]b4_final_state_number[, //< Termination state number.
       yyterror_ = 1,
       yyerrcode_ = 256,
-      yyntokens_ = ]b4_tokens_number[,   //< Number of tokens.
+      yyntokens_ = ]b4_tokens_number[    //< Number of tokens.
     };
 
 ]b4_parse_param_vars[
@@ -353,10 +361,9 @@ b4_public_types_define])[
  /* Redirection for backward compatibility.  */
 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
 #endif
-])
-b4_percent_code_get([[provides]])[]dnl
-
-[#endif /* ! defined PARSER_HEADER_H */]
+])[
+]b4_percent_code_get([[provides]])[
+]b4_cpp_guard_close([b4_spec_defines_file])
 @output(b4_parser_file_name@)@
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
 b4_percent_code_get([[top]])[]dnl
@@ -426,14 +433,14 @@ b4_percent_code_get[]dnl
     }                                           \
   } while (false)
 
-# define YY_REDUCE_PRINT(Rule)         \
-  do {                                 \
+# define YY_REDUCE_PRINT(Rule)          \
+  do {                                  \
     if (yydebug_)                       \
-      yy_reduce_print_ (Rule);         \
+      yy_reduce_print_ (Rule);          \
   } while (false)
 
-# define YY_STACK_PRINT()              \
-  do {                                 \
+# define YY_STACK_PRINT()               \
+  do {                                  \
     if (yydebug_)                       \
       yystack_print_ ();                \
   } while (false)
@@ -441,7 +448,7 @@ b4_percent_code_get[]dnl
 #else /* !YYDEBUG */
 
 # define YYCDEBUG if (false) std::cerr
-# define YY_SYMBOL_PRINT(Title, Symbol)  static_cast<void>(0)
+# define YY_SYMBOL_PRINT(Title, Symbol)  YYUSE(Symbol)
 # define YY_REDUCE_PRINT(Rule)           static_cast<void>(0)
 # define YY_STACK_PRINT()                static_cast<void>(0)
 
@@ -544,12 +551,11 @@ b4_percent_code_get[]dnl
   ]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
                                        symbol_base_type<Exact>& yysym) const
   {
-    int yytype = yysym.type_get ();
-    YYUSE (yymsg);
     if (yymsg)
       YY_SYMBOL_PRINT (yymsg, yysym);
 
     // User destructor.
+    int yytype = yysym.type_get ();
     switch (yytype)
       {
 ]b4_symbol_foreach([b4_symbol_destructor])dnl
@@ -567,6 +573,8 @@ b4_percent_code_get[]dnl
   ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
                                      const symbol_base_type<Exact>& yysym) const
   {
+    std::ostream& yyoutput = yyo;
+    YYUSE (yyoutput);
     int yytype = yysym.type_get ();
     yyo << (yytype < yyntokens_ ? "token" : "nterm")
         << ' ' << yytname_[yytype] << " ("]b4_locations_if([
@@ -575,7 +583,7 @@ b4_percent_code_get[]dnl
       {
 ]b4_symbol_foreach([b4_symbol_printer])dnl
 [       default:
-         break;
+          break;
       }
     yyo << ')';
   }
@@ -711,7 +719,7 @@ m4_popdef([b4_at_dollar])])dnl
        location values to have been already stored, initialize these
        stacks with a primary value.  */
     yystack_ = stack_type (0);
-    yypush_ (0, 0, yyla);
+    yypush_ (YY_NULL, 0, yyla);
 
     // A new symbol was pushed on the stack.
   yynewstate:
@@ -735,13 +743,21 @@ m4_popdef([b4_at_dollar])])dnl
     if (yyempty)
       {
         YYCDEBUG << "Reading a token: ";
+        try
+        {
 ]b4_lex_symbol_if(
-[        yyla = b4_c_function_call([yylex], [symbol_type],
-                                   m4_ifdef([b4_lex_param], b4_lex_param));],
-[        yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
-                                    [[YYSTYPE*], [&yyla.value]][]dnl
+[          yyla = b4_c_function_call([yylex], [symbol_type],
+                                     m4_ifdef([b4_lex_param], b4_lex_param));],
+[          yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
+                                     [[YYSTYPE*], [&yyla.value]][]dnl
 b4_locations_if([, [[location*], [&yyla.location]]])dnl
 m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
+        }
+        catch (const syntax_error& yyexc)
+        {
+          error (yyexc);
+          goto yyerrlab1;
+        }
         yyempty = false;
       }
     YY_SYMBOL_PRINT ("Next token is", yyla);
@@ -756,10 +772,10 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
     yyn = yytable_[yyn];
     if (yyn <= 0)
       {
-       if (yy_table_value_is_error_ (yyn))
-         goto yyerrlab;
-       yyn = -yyn;
-       goto yyreduce;
+        if (yy_table_value_is_error_ (yyn))
+          goto yyerrlab;
+        yyn = -yyn;
+        goto yyreduce;
       }
 
     /* Discard the token being shifted.  */
@@ -818,14 +834,13 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
       switch (yyn)
       {
 ]b4_user_actions[
-       default:
+        default:
           break;
       }
     }
     catch (const syntax_error& yyexc)
     {
-      error (]b4_args(b4_locations_if([yyexc.location]),
-                      [[yyexc.what()]])[);
+      error (yyexc);
       YYERROR;
     }
     YY_SYMBOL_PRINT ("-> $$ =", yylhs);
@@ -842,14 +857,14 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
       // in the debug trace, it's possibly junk.  Hence yymsg = 0.
       // Besides, that keeps exactly the same traces as with the other
       // Bison skeletons.
-      yy_destroy_ (0, yystack_[i]);]])[
+      yy_destroy_ (YY_NULL, yystack_[i]);]])[
 
     yypop_ (yylen);
     yylen = 0;
     YY_STACK_PRINT ();
 
     /* Shift the result of the reduction.  */
-    yypush_ (0, yylhs);
+    yypush_ (YY_NULL, yylhs);
     goto yynewstate;
 
   /*--------------------------------------.
@@ -859,8 +874,8 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
     /* If not already recovering from an error, report this error.  */
     if (!yyerrstatus_)
       {
-       ++yynerrs_;
-       error (]b4_args(b4_locations_if([yyla.location]),
+        ++yynerrs_;
+        error (]b4_args(b4_locations_if([yyla.location]),
                         [[yysyntax_error_ (yystack_[0].state,
                                            yyempty ? yyempty_ : yyla.type)]])[);
       }
@@ -869,7 +884,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
     yyerror_range[1].location = yyla.location;]])[
     if (yyerrstatus_ == 3)
       {
-       /* If just tried and failed to reuse lookahead token after an
+        /* If just tried and failed to reuse lookahead token after an
            error, discard it.  */
 
         /* Return failure if at end of input.  */
@@ -879,7 +894,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
           {
             yy_destroy_ ("Error: discarding", yyla);
             yyempty = true;
-         }
+          }
       }
 
     /* Else will try to reuse lookahead token after shifting the error
@@ -910,7 +925,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
   | yyerrlab1 -- common code for both syntax error and YYERROR.  |
   `-------------------------------------------------------------*/
   yyerrlab1:
-    yyerrstatus_ = 3;  /* Each real token shifted decrements this.  */
+    yyerrstatus_ = 3;   /* Each real token shifted decrements this.  */
     {
       stack_symbol_type error_token;
       for (;;)
@@ -965,13 +980,20 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
     yypop_ (yylen);
     while (yystack_.size () != 1)
       {
-       yy_destroy_ ("Cleanup: popping", yystack_[0]);
-       yypop_ ();
+        yy_destroy_ ("Cleanup: popping", yystack_[0]);
+        yypop_ ();
       }
 
     return yyresult;
   }
 
+  void
+  ]b4_parser_class_name[::error (const syntax_error& yyexc)
+  {
+    error (]b4_args(b4_locations_if([yyexc.location]),
+                    [[yyexc.what()]])[);
+  }
+
   // Generate an error message.
   std::string
   ]b4_parser_class_name[::yysyntax_error_ (]dnl
@@ -1040,7 +1062,7 @@ b4_error_verbose_if([state_type yystate, int yytoken],
           }
       }
 
-    char const* yyformat = 0;
+    char const* yyformat = YY_NULL;
     switch (yycount)
       {
 #define YYCASE_(N, S)                         \
@@ -1098,7 +1120,7 @@ b4_error_verbose_if([state_type yystate, int yytoken],
     for (stack_type::const_iterator
            i = yystack_.begin (),
            i_end = yystack_.end ();
-        i != i_end; ++i)
+         i != i_end; ++i)
       *yycdebug_ << ' ' << i->state;
     *yycdebug_ << std::endl;
   }
@@ -1111,7 +1133,7 @@ b4_error_verbose_if([state_type yystate, int yytoken],
     int yynrhs = yyr2_[yyrule];
     /* Print the symbols being reduced, and their result.  */
     *yycdebug_ << "Reducing stack by rule " << yyrule - 1
-              << " (line " << yylno << "):" << std::endl;
+               << " (line " << yylno << "):" << std::endl;
     /* The symbols being reduced.  */
     for (int yyi = 0; yyi < yynrhs; yyi++)
       YY_SYMBOL_PRINT ("   $" << yyi + 1 << " =",