bison-patches
[Top][All Lists]
Advanced

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

18-fyi-precsym.patch


From: Akim Demaille
Subject: 18-fyi-precsym.patch
Date: Sun, 07 Apr 2002 17:24:16 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/gram.h (rule_s): prec and precsym are now pointers
        to the bucket giving the priority/associativity.
        Member `associativity' removed: useless.
        * src/reduce.c, src/conflicts.c: Adjust.

Index: src/conflicts.c
--- src/conflicts.c Thu, 04 Apr 2002 19:44:17 +0200 akim
+++ src/conflicts.c Sat, 06 Apr 2002 17:35:51 +0200 akim
@@ -1,5 +1,6 @@
 /* Find and resolve or report look-ahead conflicts for bison,
-   Copyright 1984, 1989, 1992, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002
+   Free Software Foundation, Inc.

    This file is part of Bison, the GNU Compiler Compiler.

@@ -97,7 +98,7 @@
 {
   int i;
   /* find the rule to reduce by to get precedence of reduction  */
-  int redprec = LArule[lookahead]->prec;
+  int redprec = LArule[lookahead]->prec->prec;
   errs *errp = errs_new (ntokens + 1);
   errp->nerrs = 0;

@@ -175,6 +176,7 @@
      precedence */
   for (i = 0; i < state->nlookaheads; ++i)
     if (LArule[state->lookaheadsp + i]->prec
+       && LArule[state->lookaheadsp + i]->prec->prec
        && !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
       {
        resolve_sr_conflict (state, state->lookaheadsp + i);
Index: src/gram.h
--- src/gram.h Thu, 04 Apr 2002 19:41:33 +0200 akim
+++ src/gram.h Sat, 06 Apr 2002 17:39:23 +0200 akim
@@ -54,23 +54,24 @@

    RULES is an array of struct rule_s, which members are:

-   RULES[R].lhs -- the symbol number of the left hand side of rule R.
-   If -1, the rule has been thrown out by reduce.c and should be
-   ignored.
+   RULES[R].lhs -- the symbol of the left hand side of rule R.

    RULES[R].rhs -- the index in RITEM of the beginning of the portion
    for rule R.

-   RULES[R].prec -- the precedence level of R.
+   RULES[R].prec -- the symbol providing the precedence level of R.

-   RULES[R].precsym -- the symbol-number of the symbol in %prec for R
-   (if any).
+   RULES[R].precsym -- the symbol attached (via %prec) to give its
+   precedence to R.  Of course, if set, it is equal to `prec', but we
+   need to distinguish one from the other when reducing: a symbol used
+   in a %prec is not useless.

    RULES[R].assoc -- the associativity of R.

    RULES[R].line -- the line where R was defined.

-   RULES[R].useful -- TRUE iff the rule is used.
+   RULES[R].useful -- TRUE iff the rule is used (i.e., FALSE if thrown
+   away by reduce).

    The right hand side is stored as symbol numbers in a portion of
    RITEM.
@@ -126,9 +127,13 @@

   bucket *lhs;
   short *rhs;
-  short prec;
-  short precsym;
-  associativity assoc;
+
+  /* This symbol provides both the associativity, and the precedence. */
+  bucket *prec;
+
+  /* This symbol was attached to the rule via %prec. */
+  bucket *precsym;
+
   short line;
   bool useful;

Index: src/reader.c
--- src/reader.c Thu, 04 Apr 2002 19:41:33 +0200 akim
+++ src/reader.c Sat, 06 Apr 2002 17:38:12 +0200 akim
@@ -1705,10 +1705,7 @@
          /* A rule gets by default the precedence and associativity
             of the last token in it.  */
          if (p->sym->class == token_sym)
-           {
-             rules[ruleno].prec = p->sym->prec;
-             rules[ruleno].assoc = p->sym->assoc;
-           }
+           rules[ruleno].prec = p->sym;
          if (p)
            p = p->next;
        }
@@ -1717,11 +1714,9 @@
          the specified symbol's precedence replaces the default.  */
       if (ruleprec)
        {
-         rules[ruleno].prec = ruleprec->prec;
-         rules[ruleno].assoc = ruleprec->assoc;
-         rules[ruleno].precsym = ruleprec->number;
+         rules[ruleno].precsym = ruleprec;
+         rules[ruleno].prec = ruleprec;
        }
-
       ritem[itemno++] = -ruleno;
       ruleno++;

Index: src/reduce.c
--- src/reduce.c Sat, 06 Apr 2002 00:08:37 +0200 akim
+++ src/reduce.c Sat, 06 Apr 2002 17:37:50 +0200 akim
@@ -218,7 +218,7 @@
   /* A token that was used in %prec should not be warned about.  */
   for (i = 1; i < nrules + 1; i++)
     if (rules[i].precsym != 0)
-      bitset_set (V1, rules[i].precsym);
+      bitset_set (V1, rules[i].precsym->number);
 }


@@ -310,15 +310,6 @@
     free (symbols_sorted + ntokens);
   }

-  /* Replace all symbol numbers in valid data structures.  */
-
-  for (i = 1; i < nrules + 1; i++)
-    {
-      if (ISVAR (rules[i].precsym))
-       /* Can this happen?  */
-       rules[i].precsym = nontermmap[rules[i].precsym];
-    }
-
   for (i = 0; i < nritems; ++i)
     if (ISVAR (ritem[i]))
       ritem[i] = nontermmap[ritem[i]];
@@ -412,8 +403,11 @@
        ++rhs_count;
       fprintf (out, "%3d (%2d, %2d, %2d, %2d-%2d)   %2d ->",
               i - 1,
-              rules[i].prec, rules[i].assoc, rules[i].useful,
-              rules[i].rhs - ritem, rules[i].rhs - ritem + rhs_count - 1,
+              rules[i].prec->prec,
+              rules[i].prec->assoc,
+              rules[i].useful,
+              rules[i].rhs - ritem,
+              rules[i].rhs - ritem + rhs_count - 1,
               rules[i].lhs->number);
       /* Dumped the RHS. */
       for (r = rules[i].rhs; *r >= 0; r++)
Index: src/symtab.h
--- src/symtab.h Mon, 25 Mar 2002 21:34:54 +0100 akim
+++ src/symtab.h Sat, 06 Apr 2002 17:35:51 +0200 akim
@@ -1,5 +1,6 @@
 /* Definitions for symtab.c and callers, part of bison,
-   Copyright 1984, 1989, 1992, 2000, 2001, 2002  Free Software Foundation, Inc.
+   Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002
+   Free Software Foundation, Inc.

    This file is part of Bison, the GNU Compiler Compiler.



reply via email to

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