/[bison]/bison/src/reduce.c
ViewVC logotype

Diff of /bison/src/reduce.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38 by akim, Sat Dec 29 14:15:33 2001 UTC revision 1.39 by akim, Sat Dec 29 14:18:32 2001 UTC
# Line 28  Line 28 
28  #include "system.h"  #include "system.h"
29  #include "getargs.h"  #include "getargs.h"
30  #include "files.h"  #include "files.h"
31    #include "symtab.h"
32  #include "gram.h"  #include "gram.h"
33  #include "complain.h"  #include "complain.h"
34  #include "reduce.h"  #include "reduce.h"
# Line 353  nonterminals_reduce (void) Line 354  nonterminals_reduce (void)
354    
355    /* Shuffle elements of tables indexed by symbol number.  */    /* Shuffle elements of tables indexed by symbol number.  */
356    {    {
357      short *sassoc_sorted = XMALLOC (short, nvars) - ntokens;      bucket **symbols_sorted = XMALLOC (bucket *, nvars) - ntokens;
     short *sprec_sorted  = XMALLOC (short, nvars) - ntokens;  
     char **tags_sorted   = XMALLOC (char *, nvars) - ntokens;  
358    
359      for (i = ntokens; i < nsyms; i++)      for (i = ntokens; i < nsyms; i++)
360        {        symbols_sorted[nontermmap[i]] = symbols[i];
         n = nontermmap[i];  
         sassoc_sorted[n] = sassoc[i];  
         sprec_sorted[n]  = sprec[i];  
         tags_sorted[n]   = tags[i];  
       }  
361      for (i = ntokens; i < nsyms; i++)      for (i = ntokens; i < nsyms; i++)
362        {        symbols[i] = symbols_sorted[i];
363          sassoc[i] = sassoc_sorted[i];      free (symbols_sorted + ntokens);
         sprec[i]  = sprec_sorted[i];  
         tags[i]   = tags_sorted[i];  
       }  
     free (sassoc_sorted + ntokens);  
     free (sprec_sorted + ntokens);  
     free (tags_sorted + ntokens);  
364    }    }
365    
366    /* Replace all symbol numbers in valid data structures.  */    /* Replace all symbol numbers in valid data structures.  */
# Line 410  reduce_output (FILE *out) Line 398  reduce_output (FILE *out)
398        int i;        int i;
399        fprintf (out, "%s\n\n", _("Useless nonterminals:"));        fprintf (out, "%s\n\n", _("Useless nonterminals:"));
400        for (i = 0; i < nuseless_nonterminals; ++i)        for (i = 0; i < nuseless_nonterminals; ++i)
401          fprintf (out, "   %s\n", tags[nsyms + i]);          fprintf (out, "   %s\n", symbols[nsyms + i]->tag);
402        fputs ("\n\n", out);        fputs ("\n\n", out);
403      }      }
404    
# Line 423  reduce_output (FILE *out) Line 411  reduce_output (FILE *out)
411            if (!b)            if (!b)
412              fprintf (out, "%s\n\n", _("Terminals which are not used:"));              fprintf (out, "%s\n\n", _("Terminals which are not used:"));
413            b = TRUE;            b = TRUE;
414            fprintf (out, "   %s\n", tags[i]);            fprintf (out, "   %s\n", symbols[i]->tag);
415          }          }
416      if (b)      if (b)
417        fputs ("\n\n", out);        fputs ("\n\n", out);
# Line 438  reduce_output (FILE *out) Line 426  reduce_output (FILE *out)
426            {            {
427              rule r;              rule r;
428              fprintf (out, "#%-4d  ", i - 1);              fprintf (out, "#%-4d  ", i - 1);
429              fprintf (out, "%s:", tags[rule_table[i].lhs]);              fprintf (out, "%s:", symbols[rule_table[i].lhs]->tag);
430              for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)              for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
431                fprintf (out, " %s", tags[*r]);                fprintf (out, " %s", symbols[*r]->tag);
432              fputs (";\n", out);              fputs (";\n", out);
433            }            }
434        fputs ("\n\n", out);        fputs ("\n\n", out);
# Line 460  dump_grammar (FILE *out) Line 448  dump_grammar (FILE *out)
448    fprintf (out, "Variables\n---------\n\n");    fprintf (out, "Variables\n---------\n\n");
449    fprintf (out, "Value  Sprec  Sassoc  Tag\n");    fprintf (out, "Value  Sprec  Sassoc  Tag\n");
450    for (i = ntokens; i < nsyms; i++)    for (i = ntokens; i < nsyms; i++)
451      fprintf (out, "%5d  %5d   %5d  %s\n", i, sprec[i], sassoc[i], tags[i]);      fprintf (out, "%5d  %5d   %5d  %s\n",
452                 i,
453                 symbols[i]->prec, symbols[i]->assoc, symbols[i]->tag);
454    fprintf (out, "\n\n");    fprintf (out, "\n\n");
455    fprintf (out, "Rules\n-----\n\n");    fprintf (out, "Rules\n-----\n\n");
456    fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n");    fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n");
# Line 484  dump_grammar (FILE *out) Line 474  dump_grammar (FILE *out)
474    fprintf (out, "Rules interpreted\n-----------------\n\n");    fprintf (out, "Rules interpreted\n-----------------\n\n");
475    for (i = 1; i <= nrules; i++)    for (i = 1; i <= nrules; i++)
476      {      {
477        fprintf (out, "%-5d  %s :", i, tags[rule_table[i].lhs]);        fprintf (out, "%-5d  %s :", i, symbols[rule_table[i].lhs]->tag);
478        for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)        for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
479          fprintf (out, " %s", tags[*r]);          fprintf (out, " %s", symbols[*r]->tag);
480        fputc ('\n', out);        fputc ('\n', out);
481      }      }
482    fprintf (out, "\n\n");    fprintf (out, "\n\n");
# Line 551  reduce_grammar (void) Line 541  reduce_grammar (void)
541    
542    if (!BITISSET (N, start_symbol - ntokens))    if (!BITISSET (N, start_symbol - ntokens))
543      fatal (_("Start symbol %s does not derive any sentence"),      fatal (_("Start symbol %s does not derive any sentence"),
544             tags[start_symbol]);             symbols[start_symbol]->tag);
545    
546    reduce_grammar_tables ();    reduce_grammar_tables ();
547    if (nuseless_nonterminals > 0)    if (nuseless_nonterminals > 0)

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26