]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
Push a complete symbol, not connected parts.
[bison.git] / data / lalr1.cc
index 34bcc278df616404059c80c88bcbc5bc532d7116..93c300571c58b5b18f6f70b8c6ecc361d8414406 100644 (file)
@@ -514,12 +514,9 @@ m4_ifdef([b4_stype],
     /// Push a new state on the stack.
     /// \param m    a debug message to display
     ///             if null, no trace is output.
-    /// \param s    the state entered
-    /// \param v    semantic value
-    /// \param l    location
-    /// \warning the contents of \a v is stolen.
-    inline void yypush_ (const char* m, state_type s,
-                         semantic_type& v, const location_type& l);
+    /// \param s    the symbol
+    /// \warning the contents of \a s.value is stolen.
+    inline void yypush_ (const char* m, data_type& s);
 
     /// Pop \a n symbols the three stacks.
     inline void yypop_ (unsigned int n = 1);
@@ -757,15 +754,15 @@ b4_percent_code_get[]dnl
   }
 
   void
-  ]b4_parser_class_name[::yypush_ (const char* m, state_type s,
-                           semantic_type& v, const location_type& l)
+  ]b4_parser_class_name[::yypush_ (const char* m, data_type& s)
   {
     if (m)
-      YY_SYMBOL_PRINT (m, yystos_[s], v, l);
+      YY_SYMBOL_PRINT (m, yystos_[s.state], s.value, s.location);
 ]b4_variant_if(
 [[    yystack_.push (data_type (s, semantic_type(), l));
-    ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]], [build], [v])],
-[    yystack_.push (data_type (s, v, l));])[
+    ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]],
+                       [build], [s.value])],
+[    yystack_.push (s);])[
   }
 
   void
@@ -817,10 +814,9 @@ b4_percent_code_get[]dnl
     int yynerrs_ = 0;
     int yyerrstatus_ = 0;
 
-    /// Semantic value of the lookahead.
-    semantic_type yylval;
-    /// Location of the lookahead.
-    location_type yylloc;
+    /// The lookahead symbol.
+    data_type yyla;
+
     /// The locations where the error started and ended.
     data_type yyerror_range[2];
 
@@ -833,8 +829,8 @@ b4_percent_code_get[]dnl
     YYCDEBUG << "Starting parse" << std::endl;
 
 ]m4_ifdef([b4_initial_action], [
-m4_pushdef([b4_at_dollar],     [yylloc])dnl
-m4_pushdef([b4_dollar_dollar], [yylval])dnl
+m4_pushdef([b4_at_dollar],     [yyla.location])dnl
+m4_pushdef([b4_dollar_dollar], [yyla.value])dnl
     /* User initialization code.  */
     b4_user_initial_action
 m4_popdef([b4_dollar_dollar])dnl
@@ -845,7 +841,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, yystate, yylval, yylloc);
+    yypush_ (0, yyla);
 
     // A new state was pushed on the stack.
     // Invariant: yystate == yystack_[0].state, i.e.,
@@ -872,8 +868,8 @@ m4_popdef([b4_at_dollar])])dnl
       {
        YYCDEBUG << "Reading a token: ";
        yychar = ]b4_c_function_call([yylex], [int],
-                                    [[YYSTYPE*], [&yylval]][]dnl
-b4_locations_if([, [[location*], [&yylloc]]])dnl
+                                    [[YYSTYPE*], [&yyla.value]][]dnl
+b4_locations_if([, [[location*], [&yyla.location]]])dnl
 m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
       }
 
@@ -887,7 +883,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
     else
       {
        yytoken = yytranslate_ (yychar);
-       YY_SYMBOL_PRINT ("Next token is", yytoken, yylval, yylloc);
+       YY_SYMBOL_PRINT ("Next token is", yytoken, yyla.value, yyla.location);
       }
 
     /* If the proper action on seeing token YYTOKEN is to reduce or to
@@ -901,7 +897,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
     if (yyn <= 0)
       {
        if (yyn == 0 || yyn == yytable_ninf_)
-       goto yyerrlab;
+         goto yyerrlab;
        yyn = -yyn;
        goto yyreduce;
       }
@@ -915,8 +911,8 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
       --yyerrstatus_;
 
     /* Shift the lookahead token.  */
-    yystate = yyn;
-    yypush_ ("Shifting", yystate, yylval, yylloc);
+    yyla.state = yystate = yyn;
+    yypush_ ("Shifting", yyla);
     goto yynewstate;
 
   /*-----------------------------------------------------------.
@@ -992,7 +988,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
     YY_STACK_PRINT ();
 
     /* Shift the result of the reduction.  */
-    yypush_ (0, yylhs.state, yylhs.value, yylhs.location);
+    yypush_ (0, yylhs);
     goto yynewstate;
 
   /*------------------------------------.
@@ -1003,10 +999,10 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
     if (!yyerrstatus_)
       {
        ++yynerrs_;
-       error (yylloc, yysyntax_error_ (yystate, yytoken));
+       error (yyla.location, yysyntax_error_ (yystate, yytoken));
       }
 
-    yyerror_range[0].location = yylloc;
+    yyerror_range[0].location = yyla.location;
     if (yyerrstatus_ == 3)
       {
        /* If just tried and failed to reuse lookahead token after an
@@ -1020,7 +1016,8 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
          }
        else
          {
-           yydestruct_ ("Error: discarding", yytoken, yylval, yylloc);
+           yydestruct_ ("Error: discarding",
+                         yytoken, yyla.value, yyla.location);
            yychar = yyempty_;
          }
       }
@@ -1083,12 +1080,12 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
           YY_STACK_PRINT ();
         }
 
-      yyerror_range[1].location = yylloc;
+      yyerror_range[1].location = yyla.location;
       YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);
 
       /* Shift the error token.  */
-      yystate = yyn;
-      yypush_ ("Shifting", yystate, error_token.value, error_token.location);
+      error_token.state = yystate = yyn;
+      yypush_ ("Shifting", error_token);
     }
     goto yynewstate;
 
@@ -1104,7 +1101,8 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
 
   yyreturn:
     if (yychar != yyempty_)
-      yydestruct_ ("Cleanup: discarding lookahead", yytoken, yylval, yylloc);
+      yydestruct_ ("Cleanup: discarding lookahead",
+                   yytoken, yyla.value, yyla.location);
 
     /* Do not reclaim the symbols of the rule which action triggered
        this YYABORT or YYACCEPT.  */