]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Adjust
[bison.git] / data / lalr1.cc
index 9ac1677d804b965b21b7ded69af4d2d7c26833d6..b07cb19378c71a7e561f3c50cc8357bd29b9f479 100644 (file)
@@ -114,6 +114,35 @@ m4_define([b4_cc_var_decls],
 m4_define([b4_cc_var_decl],
          [    $1;])
 
 m4_define([b4_cc_var_decl],
          [    $1;])
 
+
+# b4_yysymprint_generate(FUNCTION-DECLARATOR)
+# -------------------------------------------
+# Generate the "symprint_" member function.
+m4_define([b4_yysymprint_generate],
+[[/*--------------------------------.
+| Print this symbol on YYOUTPUT.  |
+`--------------------------------*/
+
+]void
+yy::b4_parser_class_name::symprint_ (int yytype, const SemanticType *yyvaluep, const LocationType *yylocationp)[
+{
+  /* Pacify ``unused variable'' warnings.  */
+  (void) yyvaluep;
+  (void) yylocationp;
+
+  cdebug_ << (yytype < ntokens_ ? "token" : "nterm")
+         << ' ' << name_[yytype] << " (";
+  switch (yytype)
+    {
+]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
+[      default:
+        break;
+    }
+  cdebug_ << ')';
+}
+]])
+
+
 # b4_cxx_destruct_def(IGNORED-ARGUMENTS)
 # --------------------------------------
 # Declare the destruct_ method.
 # b4_cxx_destruct_def(IGNORED-ARGUMENTS)
 # --------------------------------------
 # Declare the destruct_ method.
@@ -122,6 +151,7 @@ m4_define([b4_cxx_destruct_def],
 yy::b4_parser_class_name::destruct_ (int yytype, SemanticType *yyvaluep, LocationType *yylocationp)[]dnl
 ])
 
 yy::b4_parser_class_name::destruct_ (int yytype, SemanticType *yyvaluep, LocationType *yylocationp)[]dnl
 ])
 
+
 # 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
@@ -161,7 +191,9 @@ b4_syncline([@oline@], [@ofile@])[
 # define YYERROR_VERBOSE ]b4_error_verbose[
 #endif
 
 # define YYERROR_VERBOSE ]b4_error_verbose[
 #endif
 
-#ifndef YYSTYPE
+#ifdef YYSTYPE
+typedef YYSTYPE yystype;
+#else
 ]m4_ifdef([b4_stype],
 [b4_syncline([b4_stype_line], [b4_filename])
 typedef union b4_stype yystype;
 ]m4_ifdef([b4_stype],
 [b4_syncline([b4_stype_line], [b4_filename])
 typedef union b4_stype yystype;
@@ -243,6 +275,12 @@ namespace yy
     virtual void error_ ();
     virtual void print_ ();
     virtual void report_syntax_error_ ();
     virtual void error_ ();
     virtual void print_ ();
     virtual void report_syntax_error_ ();
+#if YYDEBUG
+    virtual void symprint_ (int yytype,
+                           const SemanticType *yyvaluep,
+                           const LocationType *yylocationp);
+#endif /* ! YYDEBUG */
+
 
     /* Stacks.  */
     StateStack    state_stack_;
 
     /* Stacks.  */
     StateStack    state_stack_;
@@ -307,14 +345,14 @@ namespace yy
     int debug_;
     std::ostream &cdebug_;
 
     int debug_;
     std::ostream &cdebug_;
 
-    /* Lookahead and lookahead in internal form.  */
+    /* Look-ahead and look-ahead in internal form.  */
     int looka_;
     int ilooka_;
 
     /* Message.  */
     std::string message;
 
     int looka_;
     int ilooka_;
 
     /* Message.  */
     std::string message;
 
-    /* Semantic value and location of lookahead token.  */
+    /* Semantic value and location of look-ahead token.  */
     SemanticType value;
     LocationType location;
     /* Beginning of the last erroneous token popped off.  */
     SemanticType value;
     LocationType location;
     /* Beginning of the last erroneous token popped off.  */
@@ -361,6 +399,9 @@ do {                                        \
 #define YYABORT                goto yyabortlab
 #define YYERROR                goto yyerrorlab
 
 #define YYABORT                goto yyabortlab
 #define YYERROR                goto yyerrorlab
 
+#if YYDEBUG
+]b4_yysymprint_generate([b4_cxx_symprint_def])[
+#endif /* ! YYDEBUG */
 ]b4_yydestruct_generate([b4_cxx_destruct_def])[
 
 int
 ]b4_yydestruct_generate([b4_cxx_destruct_def])[
 
 int
@@ -394,12 +435,12 @@ yy::]b4_parser_class_name[::parse ()
   /* Backup.  */
  yybackup:
 
   /* Backup.  */
  yybackup:
 
-  /* Try to take a decision without lookahead.  */
+  /* Try to take a decision without look-ahead.  */
   n_ = pact_[state_];
   if (n_ == pact_ninf_)
     goto yydefault;
 
   n_ = pact_[state_];
   if (n_ == pact_ninf_)
     goto yydefault;
 
-  /* Read a lookahead token.  */
+  /* Read a look-ahead token.  */
   if (looka_ == empty_)
     {
       YYCDEBUG << "Reading a token: ";
   if (looka_ == empty_)
     {
       YYCDEBUG << "Reading a token: ";
@@ -419,15 +460,14 @@ yy::]b4_parser_class_name[::parse ()
 #if YYDEBUG
       if (debug_)
        {
 #if YYDEBUG
       if (debug_)
        {
-         YYCDEBUG << "Next token is " << looka_
-                << " (" << name_[ilooka_];
-         print_ ();
-         YYCDEBUG << ')' << std::endl;
+         cdebug_ << "Next token is ";
+         symprint_ (ilooka_, &value, &location);
+          cdebug_ << std::endl;
        }
 #endif
     }
 
        }
 #endif
     }
 
-  /* If the proper action on seeing token YYTOKEN is to reduce or to
+  /* If the proper action on seeing token ILOOKA_ is to reduce or to
      detect an error, take that action.  */
   n_ += ilooka_;
   if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_)
      detect an error, take that action.  */
   n_ += ilooka_;
   if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_)
@@ -452,7 +492,7 @@ yy::]b4_parser_class_name[::parse ()
   if (n_ == final_)
     goto yyacceptlab;
 
   if (n_ == final_)
     goto yyacceptlab;
 
-  /* Shift the lookahead token.  */
+  /* Shift the look-ahead token.  */
 #if YYDEBUG
   YYCDEBUG << "Shifting token " << looka_
            << " (" << name_[ilooka_] << "), ";
 #if YYDEBUG
   YYCDEBUG << "Shifting token " << looka_
            << " (" << name_[ilooka_] << "), ";
@@ -546,7 +586,7 @@ b4_syncline([@oline@], [@ofile@])[
   error_start_ = location.begin;
   if (errstatus_ == 3)
     {
   error_start_ = location.begin;
   if (errstatus_ == 3)
     {
-      /* If just tried and failed to reuse lookahead token after an
+      /* If just tried and failed to reuse look-ahead token after an
         error, discard it.  */
 
       /* Return failure if at end of input.  */
         error, discard it.  */
 
       /* Return failure if at end of input.  */
@@ -563,8 +603,17 @@ b4_syncline([@oline@], [@ofile@])[
                  location_stack_.pop ();
                 if (state_stack_.height () == 1)
                   YYABORT;
                  location_stack_.pop ();
                 if (state_stack_.height () == 1)
                   YYABORT;
-//              YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
-                 destruct_ (stos_[state_stack_[0]],
+#if YYDEBUG
+                 if (debug_)
+                   {
+                     cdebug_ << "Error: popping ";
+                     symprint_ (stos_[state_stack_[0]],
+                                &semantic_stack_[0],
+                               &location_stack_[0]);
+                     cdebug_ << std::endl;
+                   }
+#endif // YYDEBUG
+                destruct_ (stos_[state_stack_[0]],
                             &semantic_stack_[0],
                             &location_stack_[0]);
               }
                             &semantic_stack_[0],
                             &location_stack_[0]);
               }
@@ -572,15 +621,19 @@ b4_syncline([@oline@], [@ofile@])[
       else
         {
 #if YYDEBUG
       else
         {
 #if YYDEBUG
-          YYCDEBUG << "Discarding token " << looka_
-                  << " (" << name_[ilooka_] << ")." << std::endl;
+          if (debug_)
+            {
+              cdebug_ << "Error: discarding ";
+              symprint_ (ilooka_, &value, &location);
+              cdebug_ << std::endl;
+            }
 #endif
           destruct_ (ilooka_, &value, &location);
           looka_ = empty_;
         }
     }
 
 #endif
           destruct_ (ilooka_, &value, &location);
           looka_ = empty_;
         }
     }
 
-  /* Else will try to reuse lookahead token after shifting the error
+  /* Else will try to reuse look-ahead token after shifting the error
      token.  */
   goto yyerrlab1;
 
      token.  */
   goto yyerrlab1;
 
@@ -631,22 +684,9 @@ yyerrlab1:
 #if YYDEBUG
       if (debug_)
        {
 #if YYDEBUG
       if (debug_)
        {
-         if (stos_[state_] < ntokens_)
-           {
-             YYCDEBUG << "Error: popping token "
-                    << token_number_[stos_[state_]]
-                    << " (" << name_[stos_[state_]];
-# ifdef YYPRINT
-             YYPRINT (stderr, token_number_[stos_[state_]],
-                      semantic_stack_.top ());
-# endif
-             YYCDEBUG << ')' << std::endl;
-           }
-         else
-           {
-             YYCDEBUG << "Error: popping nonterminal ("
-                    << name_[stos_[state_]] << ')' << std::endl;
-           }
+          cdebug_ << "Error: popping ";
+          symprint_ (stos_[state_], &semantic_stack_[0], &location_stack_[0]);
+          cdebug_ << std::endl;
        }
 #endif
       destruct_ (stos_[state_], &semantic_stack_[0], &location_stack_[0]);
        }
 #endif
       destruct_ (stos_[state_], &semantic_stack_[0], &location_stack_[0]);
@@ -817,7 +857,7 @@ yy::]b4_parser_class_name[::r2_[] =
 
 #if YYDEBUG || YYERROR_VERBOSE
 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
 
 #if YYDEBUG || YYERROR_VERBOSE
 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
-   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+   First, the terminals, then, starting at NTOKENS_, nonterminals. */
 const char*
 const yy::]b4_parser_class_name[::name_[] =
 {
 const char*
 const yy::]b4_parser_class_name[::name_[] =
 {