]> git.saurik.com Git - bison.git/commitdiff
* src/gram.h (rule_t): `lhs' is now a pointer to the symbol's
authorAkim Demaille <akim@epita.fr>
Sun, 7 Apr 2002 17:38:22 +0000 (17:38 +0000)
committerAkim Demaille <akim@epita.fr>
Sun, 7 Apr 2002 17:38:22 +0000 (17:38 +0000)
bucket.
Adjust all dependencies.
* src/reduce.c (nonterminals_reduce): Don't forget to renumber the
`number' of the buckets too.
* src/gram.h: Include `symtab.h'.
(associativity): Move to...
* src/symtab.h: here.
No longer include `gram.h'.

ChangeLog
src/derives.c
src/gram.h
src/nullable.c
src/options.c
src/output.c
src/print.c
src/print_graph.c
src/reader.c
src/reduce.c
src/symtab.h

index 57c51505f5824bf6177bd9df4e0005eccbd1eefe..bf4d384eb952899b3becf64180267844a5565422 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-04-07  Akim Demaille  <akim@epita.fr>
+
+       * src/gram.h (rule_t): `lhs' is now a pointer to the symbol's
+       bucket.
+       Adjust all dependencies.
+       * src/reduce.c (nonterminals_reduce): Don't forget to renumber the
+       `number' of the buckets too.
+       * src/gram.h: Include `symtab.h'.
+       (associativity): Move to...
+       * src/symtab.h: here.
+       No longer include `gram.h'.
+
+       
 2002-04-07  Akim Demaille  <akim@epita.fr>
 
        * src/gram.h, src/gram.c (rules_rhs_length): New.
 2002-04-07  Akim Demaille  <akim@epita.fr>
 
        * src/gram.h, src/gram.c (rules_rhs_length): New.
index 39c50280ea5d29ac8d252ba3eec72fc6f8497d8c..078c7284aa7ba0e878ec7ca3f37a69d08a6bb1e9 100644 (file)
@@ -68,14 +68,13 @@ set_derives (void)
 
   p = delts;
   for (i = nrules; i > 0; i--)
 
   p = delts;
   for (i = nrules; i > 0; i--)
-    if (rules[i].useful)
-      {
-       int lhs = rules[i].lhs;
-       p->next = dset[lhs];
-       p->value = i;
-       dset[lhs] = p;
-       p++;
-      }
+    {
+      int lhs = rules[i].lhs->number;
+      p->next = dset[lhs];
+      p->value = i;
+      dset[lhs] = p;
+      p++;
+    }
 
   derives = XCALLOC (short *, nvars) - ntokens;
   q = XCALLOC (short, nvars + nrules);
 
   derives = XCALLOC (short *, nvars) - ntokens;
   q = XCALLOC (short, nvars + nrules);
index b12a8a9124da93f08c6c23bdadc3db5363b32188..087583ade78f0a759d2f53018812a39a98465f64 100644 (file)
@@ -98,6 +98,7 @@
 
    Associativities are recorded similarly in SYMBOLS[I]->assoc.  */
 
 
    Associativities are recorded similarly in SYMBOLS[I]->assoc.  */
 
+#include "symtab.h"
 
 #define        ISTOKEN(s)      ((s) < ntokens)
 #define        ISVAR(s)        ((s) >= ntokens)
 
 #define        ISTOKEN(s)      ((s) < ntokens)
 #define        ISVAR(s)        ((s) >= ntokens)
@@ -113,22 +114,13 @@ extern int nritems;
 
 extern int start_symbol;
 
 
 extern int start_symbol;
 
-/* Associativity values for tokens and rules.  */
-typedef enum
-{
-  right_assoc,
-  left_assoc,
-  non_assoc
-} associativity;
-
-
 typedef struct rule_s
 {
   /* The number of the rule in the source.  It is usually the index in
      RULES too, except if there are useless rules.  */
   short number;
 
 typedef struct rule_s
 {
   /* The number of the rule in the source.  It is usually the index in
      RULES too, except if there are useless rules.  */
   short number;
 
-  short lhs;
+  bucket *lhs;
   short *rhs;
   short prec;
   short precsym;
   short *rhs;
   short prec;
   short precsym;
index abeefdde6121c46701fcb9e55f6f20412dad1560..3fd421d3972390e6ba2cbab4e57c78dc2fd13b4f 100644 (file)
@@ -96,10 +96,10 @@ set_nullable (void)
          {
            /* This rule has an empty RHS. */
            assert (rules[ruleno].rhs[0] == -ruleno);
          {
            /* This rule has an empty RHS. */
            assert (rules[ruleno].rhs[0] == -ruleno);
-           if (rules[ruleno].useful && !nullable[rules[ruleno].lhs])
+           if (rules[ruleno].useful && !nullable[rules[ruleno].lhs->number])
              {
              {
-               nullable[rules[ruleno].lhs] = 1;
-               *s2++ = rules[ruleno].lhs;
+               nullable[rules[ruleno].lhs->number] = 1;
+               *s2++ = rules[ruleno].lhs->number;
              }
          }
       }
              }
          }
       }
@@ -109,10 +109,10 @@ set_nullable (void)
       {
        ruleno = p->value;
        if (--rcount[ruleno] == 0)
       {
        ruleno = p->value;
        if (--rcount[ruleno] == 0)
-         if (rules[ruleno].useful && !nullable[rules[ruleno].lhs])
+         if (rules[ruleno].useful && !nullable[rules[ruleno].lhs->number])
            {
            {
-             nullable[rules[ruleno].lhs] = 1;
-             *s2++ = rules[ruleno].lhs;
+             nullable[rules[ruleno].lhs->number] = 1;
+             *s2++ = rules[ruleno].lhs->number;
            }
       }
 
            }
       }
 
index 32785975e892c3822bf6ce8b675c9362e57e97df..973b6e07e578c1858ce86c815fe7f0e56e1e84be 100644 (file)
@@ -1,5 +1,5 @@
 /* Concentrate all options use in bison,
 /* Concentrate all options use in bison,
-   Copyright 2001 Free Software Foundation, Inc.
+   Copyright 2001, 2002 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -23,6 +23,7 @@
 #include "files.h"
 #include "getargs.h"
 #include "symtab.h"
 #include "files.h"
 #include "getargs.h"
 #include "symtab.h"
+#include "gram.h"
 #include "lex.h"
 #include "output.h"
 #include "options.h"
 #include "lex.h"
 #include "output.h"
 #include "options.h"
index 63b1e0dcc884caf9ad5d4d5b6e76ba931dd17126..acb453c63f496514ab269f9d164d2c506292c878 100644 (file)
@@ -300,7 +300,7 @@ output_rule_data (void)
   {
     short *values = XCALLOC (short, nrules + 1);
     for (i = 1; i < nrules + 1; ++i)
   {
     short *values = XCALLOC (short, nrules + 1);
     for (i = 1; i < nrules + 1; ++i)
-      values[i] = rules[i].lhs;
+      values[i] = rules[i].lhs->number;
     output_table_data (&format_obstack, values,
                       0, 1, nrules + 1);
     muscle_insert ("r1", obstack_finish (&format_obstack));
     output_table_data (&format_obstack, values,
                       0, 1, nrules + 1);
     muscle_insert ("r1", obstack_finish (&format_obstack));
index 9077960071fad615297486df100a6737fa915a7a..509e437b51aabf1226d36cdea0ed1661707c194f 100644 (file)
@@ -94,7 +94,7 @@ print_core (FILE *out, state_t *state)
            sp++;
 
          rule = -(*sp);
            sp++;
 
          rule = -(*sp);
-         fprintf (out, "    %s  ->  ", escape (symbols[rules[rule].lhs]->tag));
+         fprintf (out, "    %s  ->  ", escape (rules[rule].lhs->tag));
 
          for (sp = rules[rule].rhs; sp < sp1; sp++)
            fprintf (out, "%s ", escape (symbols[*sp]->tag));
 
          for (sp = rules[rule].rhs; sp < sp1; sp++)
            fprintf (out, "%s ", escape (symbols[*sp]->tag));
@@ -189,7 +189,7 @@ print_reductions (FILE *out, state_t *state)
   if (state->consistent)
     {
       int rule = redp->rules[0];
   if (state->consistent)
     {
       int rule = redp->rules[0];
-      int symbol = rules[rule].lhs;
+      int symbol = rules[rule].lhs->number;
       fprintf (out, _("    $default\treduce using rule %d (%s)\n\n"),
               rule - 1, escape (symbols[symbol]->tag));
       return;
       fprintf (out, _("    $default\treduce using rule %d (%s)\n\n"),
               rule - 1, escape (symbols[symbol]->tag));
       return;
@@ -221,10 +221,10 @@ print_reductions (FILE *out, state_t *state)
        if (bitset_test (lookaheadset, i))
          fprintf (out, _("    %-4s\t[reduce using rule %d (%s)]\n"),
                   escape (symbols[i]->tag), default_rule - 1,
        if (bitset_test (lookaheadset, i))
          fprintf (out, _("    %-4s\t[reduce using rule %d (%s)]\n"),
                   escape (symbols[i]->tag), default_rule - 1,
-                  escape2 (symbols[rules[default_rule].lhs]->tag));
+                  escape2 (rules[default_rule].lhs->tag));
 
       fprintf (out, _("    $default\treduce using rule %d (%s)\n\n"),
 
       fprintf (out, _("    $default\treduce using rule %d (%s)\n\n"),
-              default_rule - 1, escape (symbols[rules[default_rule].lhs]->tag));
+              default_rule - 1, escape (rules[default_rule].lhs->tag));
     }
   else if (state->nlookaheads >= 1)
     {
     }
   else if (state->nlookaheads >= 1)
     {
@@ -276,7 +276,7 @@ print_reductions (FILE *out, state_t *state)
                               _("    %-4s\treduce using rule %d (%s)\n"),
                               escape (symbols[i]->tag),
                               LAruleno[state->lookaheadsp + j] - 1,
                               _("    %-4s\treduce using rule %d (%s)\n"),
                               escape (symbols[i]->tag),
                               LAruleno[state->lookaheadsp + j] - 1,
-                              escape2 (symbols[rules[LAruleno[state->lookaheadsp + j]].lhs]->tag));
+                              escape2 (rules[LAruleno[state->lookaheadsp + j]].lhs->tag));
                    else
                      defaulted = 1;
 
                    else
                      defaulted = 1;
 
@@ -289,13 +289,13 @@ print_reductions (FILE *out, state_t *state)
                               _("    %-4s\treduce using rule %d (%s)\n"),
                               escape (symbols[i]->tag),
                               LAruleno[default_LA] - 1,
                               _("    %-4s\treduce using rule %d (%s)\n"),
                               escape (symbols[i]->tag),
                               LAruleno[default_LA] - 1,
-                              escape2 (symbols[rules[LAruleno[default_LA]].lhs]->tag));
+                              escape2 (rules[LAruleno[default_LA]].lhs->tag));
                    defaulted = 0;
                    fprintf (out,
                             _("    %-4s\t[reduce using rule %d (%s)]\n"),
                             escape (symbols[i]->tag),
                             LAruleno[state->lookaheadsp + j] - 1,
                    defaulted = 0;
                    fprintf (out,
                             _("    %-4s\t[reduce using rule %d (%s)]\n"),
                             escape (symbols[i]->tag),
                             LAruleno[state->lookaheadsp + j] - 1,
-                            escape2 (symbols[rules[LAruleno[state->lookaheadsp + j]].lhs]->tag));
+                            escape2 (rules[LAruleno[state->lookaheadsp + j]].lhs->tag));
                  }
              }
        }
                  }
              }
        }
@@ -303,7 +303,7 @@ print_reductions (FILE *out, state_t *state)
       if (default_LA >= 0)
        fprintf (out, _("    $default\treduce using rule %d (%s)\n"),
                 default_rule - 1,
       if (default_LA >= 0)
        fprintf (out, _("    $default\treduce using rule %d (%s)\n"),
                 default_rule - 1,
-                escape (symbols[rules[default_rule].lhs]->tag));
+                escape (rules[default_rule].lhs->tag));
     }
 }
 
     }
 }
 
@@ -368,7 +368,7 @@ print_grammar (FILE *out)
   for (i = 1; i < nrules + 1; i++)
     {
       fprintf (out, _("  %3d %3d %s ->"),
   for (i = 1; i < nrules + 1; i++)
     {
       fprintf (out, _("  %3d %3d %s ->"),
-              i - 1, rules[i].line, escape (symbols[rules[i].lhs]->tag));
+              i - 1, rules[i].line, escape (rules[i].lhs->tag));
       rule = rules[i].rhs;
       if (*rule >= 0)
        while (*rule >= 0)
       rule = rules[i].rhs;
       if (*rule >= 0)
        while (*rule >= 0)
@@ -411,7 +411,7 @@ print_grammar (FILE *out)
 
       for (j = 1; j < nrules + 1; j++)
        {
 
       for (j = 1; j < nrules + 1; j++)
        {
-         if (rules[j].lhs == i)
+         if (rules[j].lhs->number == i)
            left_count++;
          for (rule = rules[j].rhs; *rule >= 0; rule++)
            if (*rule == i)
            left_count++;
          for (rule = rules[j].rhs; *rule >= 0; rule++)
            if (*rule == i)
@@ -435,7 +435,7 @@ print_grammar (FILE *out)
          for (j = 1; j < nrules + 1; j++)
            {
              END_TEST (65);
          for (j = 1; j < nrules + 1; j++)
            {
              END_TEST (65);
-             if (rules[j].lhs == i)
+             if (rules[j].lhs->number == i)
                sprintf (buffer + strlen (buffer), " %d", j - 1);
            }
        }
                sprintf (buffer + strlen (buffer), " %d", j - 1);
            }
        }
index 252a2f60ade59fe279b62b8e7eacd464b49d3a5d..2570ab58d445806cd5b771ae2c02fb358867ec16 100644 (file)
@@ -78,7 +78,7 @@ print_core (state_t *state, struct obstack *node_obstack)
       if (i)
        obstack_1grow (node_obstack, '\n');
       obstack_fgrow1 (node_obstack, " %s -> ",
       if (i)
        obstack_1grow (node_obstack, '\n');
       obstack_fgrow1 (node_obstack, " %s -> ",
-                     escape (symbols[rules[rule].lhs]->tag));
+                     escape (rules[rule].lhs->tag));
 
       for (sp = rules[rule].rhs; sp < sp1; sp++)
        obstack_fgrow1 (node_obstack, "%s ", escape (symbols[*sp]->tag));
 
       for (sp = rules[rule].rhs; sp < sp1; sp++)
        obstack_fgrow1 (node_obstack, "%s ", escape (symbols[*sp]->tag));
index b0b9d88582f81ee09c6c14f70fd101078339318b..08cf4d454fbb5db16304760b27d60c3b2feb4b19 100644 (file)
@@ -1688,7 +1688,7 @@ packgram (void)
     {
       bucket *ruleprec = p->ruleprec;
       rules[ruleno].number = ruleno;
     {
       bucket *ruleprec = p->ruleprec;
       rules[ruleno].number = ruleno;
-      rules[ruleno].lhs = p->sym->number;
+      rules[ruleno].lhs = p->sym;
       rules[ruleno].rhs = ritem + itemno;
       rules[ruleno].line = p->line;
       rules[ruleno].useful = TRUE;
       rules[ruleno].rhs = ritem + itemno;
       rules[ruleno].line = p->line;
       rules[ruleno].useful = TRUE;
index b7a7f45685309da5de1b46135009a1e0557de5d9..db033b34113a7aab9c7b3e9eaf2fe196ec5d7b4b 100644 (file)
@@ -118,7 +118,7 @@ useless_nonterminals (void)
        if (!bitset_test (P, i)
            && useful_production (i, N))
          {
        if (!bitset_test (P, i)
            && useful_production (i, N))
          {
-           bitset_set (Np, rules[i].lhs - ntokens);
+           bitset_set (Np, rules[i].lhs->number - ntokens);
            bitset_set (P, i);
          }
       if (bitset_equal_p (N, Np))
            bitset_set (P, i);
          }
       if (bitset_equal_p (N, Np))
@@ -178,7 +178,7 @@ inaccessable_symbols (void)
            {
              if (!bitset_test (Pp, i)
                  && bitset_test (P, i)
            {
              if (!bitset_test (Pp, i)
                  && bitset_test (P, i)
-                 && bitset_test (V, rules[i].lhs))
+                 && bitset_test (V, rules[i].lhs->number))
                {
                  for (r = rules[i].rhs; *r >= 0; r++)
                    if (ISTOKEN (t = *r) || bitset_test (N, t - ntokens))
                {
                  for (r = rules[i].rhs; *r >= 0; r++)
                    if (ISTOKEN (t = *r) || bitset_test (N, t - ntokens))
@@ -307,6 +307,8 @@ nonterminals_reduce (void)
   {
     bucket **symbols_sorted = XMALLOC (bucket *, nvars) - ntokens;
 
   {
     bucket **symbols_sorted = XMALLOC (bucket *, nvars) - ntokens;
 
+    for (i = ntokens; i < nsyms; i++)
+      symbols[i]->number = nontermmap[i];
     for (i = ntokens; i < nsyms; i++)
       symbols_sorted[nontermmap[i]] = symbols[i];
     for (i = ntokens; i < nsyms; i++)
     for (i = ntokens; i < nsyms; i++)
       symbols_sorted[nontermmap[i]] = symbols[i];
     for (i = ntokens; i < nsyms; i++)
@@ -318,7 +320,6 @@ nonterminals_reduce (void)
 
   for (i = 1; i < nrules + 1; i++)
     {
 
   for (i = 1; i < nrules + 1; i++)
     {
-      rules[i].lhs = nontermmap[rules[i].lhs];
       if (ISVAR (rules[i].precsym))
        /* Can this happen?  */
        rules[i].precsym = nontermmap[rules[i].precsym];
       if (ISVAR (rules[i].precsym))
        /* Can this happen?  */
        rules[i].precsym = nontermmap[rules[i].precsym];
@@ -376,7 +377,7 @@ reduce_output (FILE *out)
        {
          rule r;
          fprintf (out, "#%-4d  ", rules[i].number - 1);
        {
          rule r;
          fprintf (out, "#%-4d  ", rules[i].number - 1);
-         fprintf (out, "%s:", symbols[rules[i].lhs]->tag);
+         fprintf (out, "%s:", rules[i].lhs->tag);
          for (r = rules[i].rhs; *r >= 0; r++)
            fprintf (out, " %s", symbols[*r]->tag);
          fputs (";\n", out);
          for (r = rules[i].rhs; *r >= 0; r++)
            fprintf (out, " %s", symbols[*r]->tag);
          fputs (";\n", out);
@@ -414,7 +415,7 @@ dump_grammar (FILE *out)
               i - 1,
               rules[i].prec, rules[i].assoc, rules[i].useful,
               rules[i].rhs - ritem, rules[i].rhs - ritem + rhs_count - 1,
               i - 1,
               rules[i].prec, rules[i].assoc, rules[i].useful,
               rules[i].rhs - ritem, rules[i].rhs - ritem + rhs_count - 1,
-              rules[i].lhs);
+              rules[i].lhs->number);
       /* Dumped the RHS. */
       for (r = rules[i].rhs; *r >= 0; r++)
        fprintf (out, "%3d", *r);
       /* Dumped the RHS. */
       for (r = rules[i].rhs; *r >= 0; r++)
        fprintf (out, "%3d", *r);
@@ -424,7 +425,7 @@ dump_grammar (FILE *out)
   fprintf (out, "Rules interpreted\n-----------------\n\n");
   for (i = 1; i < nrules + nuseless_productions + 1; i++)
     {
   fprintf (out, "Rules interpreted\n-----------------\n\n");
   for (i = 1; i < nrules + nuseless_productions + 1; i++)
     {
-      fprintf (out, "%-5d  %s :", i, symbols[rules[i].lhs]->tag);
+      fprintf (out, "%-5d  %s :", i, rules[i].lhs->tag);
       for (r = rules[i].rhs; *r >= 0; r++)
        fprintf (out, " %s", symbols[*r]->tag);
       fputc ('\n', out);
       for (r = rules[i].rhs; *r >= 0; r++)
        fprintf (out, " %s", symbols[*r]->tag);
       fputc ('\n', out);
index ccdfa0ee7cfcaa01b92a46748d783c4dc165956d..82892ade92a0f2c075c711184ee2a4455ed00b27 100644 (file)
@@ -1,5 +1,5 @@
 /* Definitions for symtab.c and callers, part of bison,
 /* Definitions for symtab.c and callers, part of bison,
-   Copyright 1984, 1989, 1992, 2000, 2001  Free Software Foundation, Inc.
+   Copyright 1984, 1989, 1992, 2000, 2001, 2002  Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
    This file is part of Bison, the GNU Compiler Compiler.
 
 
 #ifndef SYMTAB_H_
 # define SYMTAB_H_
 
 #ifndef SYMTAB_H_
 # define SYMTAB_H_
-# include "gram.h"
 
 #define        TABSIZE 1009
 
 
 #define        TABSIZE 1009
 
-/*  symbol classes  */
+/* Associativity values for tokens and rules.  */
+typedef enum
+{
+  right_assoc,
+  left_assoc,
+  non_assoc
+} associativity;
+
 
 
+/* Symbol classes.  */
 typedef enum
 {
   unknown_sym,
 typedef enum
 {
   unknown_sym,