bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: Parser::pop


From: Akim Demaille
Subject: FYI: Parser::pop
Date: Mon, 06 Sep 2004 16:31:04 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Minor factoring, but existing in C parsers (as a macro).

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * data/lalr1.cc: Adjust the indentation of the labels.
        (Parser::pop): New.
        Use it.

Index: data/lalr1.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/lalr1.cc,v
retrieving revision 1.52
diff -u -u -r1.52 lalr1.cc
--- data/lalr1.cc 6 Sep 2004 10:29:52 -0000 1.52
+++ data/lalr1.cc 6 Sep 2004 14:29:52 -0000
@@ -284,6 +284,9 @@
                            int yytype,
                            SemanticType *yyvaluep, LocationType *yylocationp);
 
+    /// Pop \a n symbols the three stacks.
+    inline void pop (unsigned int n = 1);
+
     /* Constants.  */
     static const int eof_;
     /* LAST_ -- Last index in TABLE_.  */
@@ -428,6 +431,14 @@
     }
 }
 
+void
+yy::]b4_parser_class_name[::pop (unsigned int n)
+{
+  state_stack_.pop (n);
+  semantic_stack_.pop (n);
+  location_stack_.pop (n);
+}
+
 int
 yy::]b4_parser_class_name[::parse ()
 {
@@ -451,13 +462,13 @@
   YYCDEBUG << "Starting parse" << std::endl;
 
   /* New state.  */
- yynewstate:
+yynewstate:
   state_stack_.push (state_);
   YYCDEBUG << "Entering state " << state_ << std::endl;
   goto yybackup;
 
   /* Backup.  */
- yybackup:
+yybackup:
 
   /* Try to take a decision without look-ahead.  */
   n_ = pact_[state_];
@@ -532,7 +543,7 @@
 /*-----------------------------------------------------------.
 | yydefault -- do the default action for the current state.  |
 `-----------------------------------------------------------*/
- yydefault:
+yydefault:
   n_ = defact_[state_];
   if (n_ == 0)
     goto yyerrlab;
@@ -541,7 +552,7 @@
 /*-----------------------------.
 | yyreduce -- Do a reduction.  |
 `-----------------------------*/
- yyreduce:
+yyreduce:
   len_ = r2_[n_];
   /* If LEN_ is nonzero, implement the default value of the action:
      `$$ = $1'.  Otherwise, use the top of the stack.
@@ -574,9 +585,7 @@
 ]/* Line __line__ of lalr1.cc.  */
 b4_syncline(address@hidden@], address@hidden@])[
 
-  state_stack_.pop (len_);
-  semantic_stack_.pop (len_);
-  location_stack_.pop (len_);
+  pop (len_);
 
   YY_STACK_PRINT ();
 
@@ -614,9 +623,7 @@
             for (;;)
               {
                  error_start_ = location_stack_[0].begin;
-                 state_stack_.pop ();
-                 semantic_stack_.pop ();
-                 location_stack_.pop ();
+                 pop ();
                 if (state_stack_.height () == 1)
                   YYABORT;
                  destruct_ ("Error: popping",
@@ -649,10 +656,8 @@
      goto yyerrorlab;
 #endif
 
-  state_stack_.pop (len_);
-  semantic_stack_.pop (len_);
   error_start_ = location_stack_[len_ - 1].begin;
-  location_stack_.pop (len_);
+  pop (len_);
   state_ = state_stack_[0];
   goto yyerrlab1;
 
@@ -684,9 +689,7 @@
                  stos_[state_], &semantic_stack_[0], &location_stack_[0]);
       error_start_ = location_stack_[0].begin;
 
-      state_stack_.pop ();
-      semantic_stack_.pop ();
-      location_stack_.pop ();
+      pop ();
       state_ = state_stack_[0];
       YY_STACK_PRINT ();
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]