]> git.saurik.com Git - bison.git/commitdiff
* src/gram.h, src/gram.c (symbols): New, similar to state_table
authorAkim Demaille <akim@epita.fr>
Sat, 29 Dec 2001 14:18:32 +0000 (14:18 +0000)
committerAkim Demaille <akim@epita.fr>
Sat, 29 Dec 2001 14:18:32 +0000 (14:18 +0000)
and rule_table.
* src/reader.c (packsymbols): Fill this table.
Drop sprec.
* src/conflicts.c (resolve_sr_conflict): Adjust.
* src/reduce.c (reduce_grammar): Adjust: just sort symbols, a
single table.
Use symbols[i]->tag instead of tags[i].

ChangeLog
src/LR0.c
src/conflicts.c
src/gram.c
src/gram.h
src/reader.c
src/reduce.c

index 381981295967537f1bb9502aeb04f80c52835d10..6d3ba670fb88b5deb4c49b43f6b1df14a3e8d5e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2001-12-29  Akim Demaille  <akim@epita.fr>
+
+       * src/gram.h, src/gram.c (symbols): New, similar to state_table
+       and rule_table.
+       * src/reader.c (packsymbols): Fill this table.
+       Drop sprec.
+       * src/conflicts.c (resolve_sr_conflict): Adjust.
+       * src/reduce.c (reduce_grammar): Adjust: just sort symbols, a
+       single table.
+       Use symbols[i]->tag instead of tags[i].
+
+       
 2001-12-29  Akim Demaille  <akim@epita.fr>
 
        * tests/calc.at (_AT_DATA_CALC_Y): Also use %union.
 2001-12-29  Akim Demaille  <akim@epita.fr>
 
        * tests/calc.at (_AT_DATA_CALC_Y): Also use %union.
index b80cede7f42e80e10550460d03b272fa19ec6cae..47ce6dd2c613346e6309092327a82171cf85fcf9 100644 (file)
--- a/src/LR0.c
+++ b/src/LR0.c
@@ -23,6 +23,7 @@
    The entry point is generate_states.  */
 
 #include "system.h"
    The entry point is generate_states.  */
 
 #include "system.h"
+#include "symtab.h"
 #include "getargs.h"
 #include "reader.h"
 #include "gram.h"
 #include "getargs.h"
 #include "reader.h"
 #include "gram.h"
index 2f9b4c247892bff531b47a9e4f7adab1487774da..a17157a65d402ba8cde7e4f80f8d492c9bdcf3f0 100644 (file)
@@ -21,6 +21,7 @@
 #include "system.h"
 #include "complain.h"
 #include "getargs.h"
 #include "system.h"
 #include "complain.h"
 #include "getargs.h"
+#include "symtab.h"
 #include "files.h"
 #include "gram.h"
 #include "state.h"
 #include "files.h"
 #include "gram.h"
 #include "state.h"
@@ -99,17 +100,17 @@ resolve_sr_conflict (state_t *state, int lookahead)
   for (i = 0; i < ntokens; i++)
     if (BITISSET (LA (lookahead), i)
        && BITISSET (lookaheadset, i)
   for (i = 0; i < ntokens; i++)
     if (BITISSET (LA (lookahead), i)
        && BITISSET (lookaheadset, i)
-       && sprec[i])
+       && symbols[i]->prec)
       {
        /* Shift-reduce conflict occurs for token number i
           and it has a precedence.
           The precedence of shifting is that of token i.  */
       {
        /* Shift-reduce conflict occurs for token number i
           and it has a precedence.
           The precedence of shifting is that of token i.  */
-       if (sprec[i] < redprec)
+       if (symbols[i]->prec < redprec)
          {
            log_resolution (state, lookahead, i, _("reduce"));
            flush_shift (state, i);
          }
          {
            log_resolution (state, lookahead, i, _("reduce"));
            flush_shift (state, i);
          }
-       else if (sprec[i] > redprec)
+       else if (symbols[i]->prec > redprec)
          {
            log_resolution (state, lookahead, i, _("shift"));
            flush_reduce (lookahead, i);
          {
            log_resolution (state, lookahead, i, _("shift"));
            flush_reduce (lookahead, i);
index 4ec973c121a74161cae5d598fa2fa66c7165f9ee..ffab36d3b606126e8a9c769ed5c3489fb3dd2ddc 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "system.h"
 #include "gram.h"
 
 #include "system.h"
 #include "gram.h"
+#include "symtab.h"
 #include "reader.h"
 
 /* comments for these variables are in gram.h  */
 #include "reader.h"
 
 /* comments for these variables are in gram.h  */
@@ -37,6 +38,8 @@ int nritems;
 rule_t *rule_table = NULL;
 short *rprec = NULL;
 short *rprecsym = NULL;
 rule_t *rule_table = NULL;
 short *rprec = NULL;
 short *rprecsym = NULL;
+
+struct bucket **symbols = NULL;
 short *sprec = NULL;
 short *rassoc = NULL;
 short *sassoc = NULL;
 short *sprec = NULL;
 short *rassoc = NULL;
 short *sassoc = NULL;
index 336c38ed3ac6d727f0a4960469e46449cbaae776..b8d1c93bb81fea61eff14b1898f76bfa22389235 100644 (file)
@@ -133,6 +133,9 @@ typedef struct rule_s
 
 extern struct rule_s *rule_table;
 
 
 extern struct rule_s *rule_table;
 
+/* Table of the symbols, indexed by the symbol number. */
+extern struct bucket **symbols;
+
 /* token translation table: indexed by a token number as returned by
    the user's yylex routine, it yields the internal token number used
    by the parser and throughout bison.  */
 /* token translation table: indexed by a token number as returned by
    the user's yylex routine, it yields the internal token number used
    by the parser and throughout bison.  */
index bebbc1539b494ff3ab31b817aa1a9b3d36c029c8..c1cbb097fafb4a50e52fd4d3b025dc10aba08fc5 100644 (file)
@@ -1556,11 +1556,10 @@ token_translations_init (void)
 }
 
 
 }
 
 
-/*------------------------------------------------------------------.
-| Assign symbol numbers, and write definition of token names into   |
-| FDEFINES.  Set up vectors TAGS and SPREC of names and precedences |
-| of symbols.                                                       |
-`------------------------------------------------------------------*/
+/*----------------------------------------------------------------.
+| Assign symbol numbers, and write definition of token names into |
+| FDEFINES.  Set up vectors SYMBOL_TABLE, TAGS of symbols.        |
+`----------------------------------------------------------------*/
 
 static void
 packsymbols (void)
 
 static void
 packsymbols (void)
@@ -1571,8 +1570,8 @@ packsymbols (void)
 
   tags = XCALLOC (char *, nsyms + 1);
   user_toknums = XCALLOC (short, nsyms + 1);
 
   tags = XCALLOC (char *, nsyms + 1);
   user_toknums = XCALLOC (short, nsyms + 1);
+  symbols = XCALLOC (bucket *, nsyms);
 
 
-  sprec = XCALLOC (short, nsyms);
   sassoc = XCALLOC (short, nsyms);
 
   max_user_token_number = 256;
   sassoc = XCALLOC (short, nsyms);
 
   max_user_token_number = 256;
@@ -1644,9 +1643,9 @@ packsymbols (void)
            max_user_token_number = bp->user_token_number;
        }
 
            max_user_token_number = bp->user_token_number;
        }
 
+      symbols[bp->value] = bp;
       tags[bp->value] = bp->tag;
       user_toknums[bp->value] = bp->user_token_number;
       tags[bp->value] = bp->tag;
       user_toknums[bp->value] = bp->user_token_number;
-      sprec[bp->value] = bp->prec;
       sassoc[bp->value] = bp->assoc;
     }
 
       sassoc[bp->value] = bp->assoc;
     }
 
index 430e5b0809b04710d936f6ad6a092551bfbee23a..83909619ab296456dbf64a7c0a28bdefd4926f8e 100644 (file)
@@ -28,6 +28,7 @@
 #include "system.h"
 #include "getargs.h"
 #include "files.h"
 #include "system.h"
 #include "getargs.h"
 #include "files.h"
+#include "symtab.h"
 #include "gram.h"
 #include "complain.h"
 #include "reduce.h"
 #include "gram.h"
 #include "complain.h"
 #include "reduce.h"
@@ -353,26 +354,13 @@ nonterminals_reduce (void)
 
   /* Shuffle elements of tables indexed by symbol number.  */
   {
 
   /* Shuffle elements of tables indexed by symbol number.  */
   {
-    short *sassoc_sorted = XMALLOC (short, nvars) - ntokens;
-    short *sprec_sorted  = XMALLOC (short, nvars) - ntokens;
-    char **tags_sorted   = XMALLOC (char *, nvars) - ntokens;
+    bucket **symbols_sorted = XMALLOC (bucket *, nvars) - ntokens;
 
     for (i = ntokens; i < nsyms; i++)
 
     for (i = ntokens; i < nsyms; i++)
-      {
-       n = nontermmap[i];
-       sassoc_sorted[n] = sassoc[i];
-       sprec_sorted[n]  = sprec[i];
-       tags_sorted[n]   = tags[i];
-      }
+      symbols_sorted[nontermmap[i]] = symbols[i];
     for (i = ntokens; i < nsyms; i++)
     for (i = ntokens; i < nsyms; i++)
-      {
-       sassoc[i] = sassoc_sorted[i];
-       sprec[i]  = sprec_sorted[i];
-       tags[i]   = tags_sorted[i];
-      }
-    free (sassoc_sorted + ntokens);
-    free (sprec_sorted + ntokens);
-    free (tags_sorted + ntokens);
+      symbols[i] = symbols_sorted[i];
+    free (symbols_sorted + ntokens);
   }
 
   /* Replace all symbol numbers in valid data structures.  */
   }
 
   /* Replace all symbol numbers in valid data structures.  */
@@ -410,7 +398,7 @@ reduce_output (FILE *out)
       int i;
       fprintf (out, "%s\n\n", _("Useless nonterminals:"));
       for (i = 0; i < nuseless_nonterminals; ++i)
       int i;
       fprintf (out, "%s\n\n", _("Useless nonterminals:"));
       for (i = 0; i < nuseless_nonterminals; ++i)
-       fprintf (out, "   %s\n", tags[nsyms + i]);
+       fprintf (out, "   %s\n", symbols[nsyms + i]->tag);
       fputs ("\n\n", out);
     }
 
       fputs ("\n\n", out);
     }
 
@@ -423,7 +411,7 @@ reduce_output (FILE *out)
          if (!b)
            fprintf (out, "%s\n\n", _("Terminals which are not used:"));
          b = TRUE;
          if (!b)
            fprintf (out, "%s\n\n", _("Terminals which are not used:"));
          b = TRUE;
-         fprintf (out, "   %s\n", tags[i]);
+         fprintf (out, "   %s\n", symbols[i]->tag);
        }
     if (b)
       fputs ("\n\n", out);
        }
     if (b)
       fputs ("\n\n", out);
@@ -438,9 +426,9 @@ reduce_output (FILE *out)
          {
            rule r;
            fprintf (out, "#%-4d  ", i - 1);
          {
            rule r;
            fprintf (out, "#%-4d  ", i - 1);
-           fprintf (out, "%s:", tags[rule_table[i].lhs]);
+           fprintf (out, "%s:", symbols[rule_table[i].lhs]->tag);
            for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
            for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
-             fprintf (out, " %s", tags[*r]);
+             fprintf (out, " %s", symbols[*r]->tag);
            fputs (";\n", out);
          }
       fputs ("\n\n", out);
            fputs (";\n", out);
          }
       fputs ("\n\n", out);
@@ -460,7 +448,9 @@ dump_grammar (FILE *out)
   fprintf (out, "Variables\n---------\n\n");
   fprintf (out, "Value  Sprec  Sassoc  Tag\n");
   for (i = ntokens; i < nsyms; i++)
   fprintf (out, "Variables\n---------\n\n");
   fprintf (out, "Value  Sprec  Sassoc  Tag\n");
   for (i = ntokens; i < nsyms; i++)
-    fprintf (out, "%5d  %5d   %5d  %s\n", i, sprec[i], sassoc[i], tags[i]);
+    fprintf (out, "%5d  %5d   %5d  %s\n",
+            i,
+            symbols[i]->prec, symbols[i]->assoc, symbols[i]->tag);
   fprintf (out, "\n\n");
   fprintf (out, "Rules\n-----\n\n");
   fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n");
   fprintf (out, "\n\n");
   fprintf (out, "Rules\n-----\n\n");
   fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n");
@@ -484,9 +474,9 @@ dump_grammar (FILE *out)
   fprintf (out, "Rules interpreted\n-----------------\n\n");
   for (i = 1; i <= nrules; i++)
     {
   fprintf (out, "Rules interpreted\n-----------------\n\n");
   for (i = 1; i <= nrules; i++)
     {
-      fprintf (out, "%-5d  %s :", i, tags[rule_table[i].lhs]);
+      fprintf (out, "%-5d  %s :", i, symbols[rule_table[i].lhs]->tag);
       for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
       for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
-       fprintf (out, " %s", tags[*r]);
+       fprintf (out, " %s", symbols[*r]->tag);
       fputc ('\n', out);
     }
   fprintf (out, "\n\n");
       fputc ('\n', out);
     }
   fprintf (out, "\n\n");
@@ -551,7 +541,7 @@ reduce_grammar (void)
 
   if (!BITISSET (N, start_symbol - ntokens))
     fatal (_("Start symbol %s does not derive any sentence"),
 
   if (!BITISSET (N, start_symbol - ntokens))
     fatal (_("Start symbol %s does not derive any sentence"),
-          tags[start_symbol]);
+          symbols[start_symbol]->tag);
 
   reduce_grammar_tables ();
   if (nuseless_nonterminals > 0)
 
   reduce_grammar_tables ();
   if (nuseless_nonterminals > 0)