bison-patches
[Top][All Lists]
Advanced

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

05-grammar-rule-symbol-or-action-append.patch


From: Akim Demaille
Subject: 05-grammar-rule-symbol-or-action-append.patch
Date: Tue, 11 Jun 2002 10:06:05 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/reader.c  (parse_action): Don't store directly into the
        rule's action member: return the action as a string.
        Don't require `rule_length' as an argument: compute it.
        (grammar_current_rule_symbol_append)
        (grammar_current_rule_action_append): New, eved out from
        (readgram): here.
        Remove `action_flag', `rulelength', unused now.

Index: src/reader.c
--- src/reader.c Mon, 10 Jun 2002 22:15:41 +0200 akim (bison/b/5_reader.c 
1.77.1.3.1.18.1.7.1.4 664)
+++ src/reader.c Mon, 10 Jun 2002 23:46:39 +0200 akim (bison/b/5_reader.c 
1.77.1.3.1.18.1.7.1.4 664)
@@ -966,19 +966,24 @@
 
 /*------------------------------------------------------------------.
 | Assuming that a `{' has just been seen, copy everything up to the |
-| matching `}' into ACTION_OBSTACK.                                 |
-|                                                                   |
-| RULE_LENGTH is the number of values in the current rule so far,   |
-| which says where to find `$0' with respect to the top of the      |
-| stack.  It is not the same as the rule->length in the case of mid |
-| rule actions.                                                     |
+| matching `}' into ACTION_OBSTACK, and return a pointer to this    |
+| action.                                                           |
 `------------------------------------------------------------------*/

-static void
-parse_action (symbol_list *rule, int rule_length)
+static char *
+parse_action (symbol_list *rule)
 {
   int count = 1;
-  rule->action_line = lineno;
+
+  /* RULE_LENGTH is the number of values in the current rule so far,
+     which says where to find `$0' with respect to the top of the
+     stack.  It is not the same as the rule->length in the case of mid
+     rule actions.  */
+  int rule_length = 0;
+  symbol_list *rhs;
+  for (rhs = rule->next; rhs; rhs = rhs->next)
+    ++rule_length;
+
   while (count > 0)
     {
       int c;
@@ -1025,7 +1030,7 @@
     }

   obstack_1grow (&action_obstack, '\0');
-  rule->action = obstack_finish (&action_obstack);
+  return obstack_finish (&action_obstack);
 }

 
@@ -1210,6 +1215,33 @@
 }


+/* Attach a SYMBOL to the current rule.  If needed, move the previous
+   action as a mid-rule action.  */
+
+static void
+grammar_current_rule_symbol_append (symbol_t *symbol)
+{
+  if (current_rule->action)
+    grammar_midrule_action ();
+  ++nritems;
+  grammar_symbol_append (symbol);
+}
+
+
+/* Attach an ACTION to the current rule.  If needed, move the previous
+   action as a mid-rule action.  */
+
+static void
+grammar_current_rule_action_append (char *action, int action_line)
+{
+  if (current_rule->action)
+    grammar_midrule_action ();
+  current_rule->action = action;
+  current_rule->action_line = action_line;
+}
+
+
+
 static void
 readgram (void)
 {
@@ -1221,10 +1253,6 @@
   while (t != tok_two_percents && t != tok_eof)
     if (t == tok_identifier || t == tok_bar)
       {
-       int action_flag = 0;
-       /* Number of symbols in rhs of this rule so far */
-       int rulelength = 0;
-
        if (t == tok_identifier)
          {
            lhs = symval;
@@ -1278,26 +1306,16 @@
                   rule's rhs.  */
              }

-           /* If we just passed an action, that action was in the middle
-              of a rule, so make a dummy rule to reduce it to a
-              non-terminal.  */
-           if (action_flag)
-             {
-               grammar_midrule_action ();
-               action_flag = 0;
-             }
-
            if (t == tok_identifier)
              {
-               ++nritems;
-               grammar_symbol_append (symval);
+               grammar_current_rule_symbol_append (symval);
              }
            else                /* handle an action.  */
              {
-               parse_action (current_rule, rulelength);
-               action_flag = 1;
+               int action_line = lineno;
+               char *action = parse_action (current_rule);
+               grammar_current_rule_action_append (action, action_line);
              }
-           ++rulelength;
          }                     /* end of  read rhs of rule */

        /* Put an empty link in the list to mark the end of this rule  */
@@ -1312,8 +1330,9 @@

        if (t == tok_left_curly)
          {
-           parse_action (current_rule, rulelength);
-           action_flag = 1;
+           int action_line = lineno;
+           char *action = parse_action (current_rule);
+           grammar_current_rule_action_append (action, action_line);
            t = lex ();
          }



reply via email to

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