/[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.70 by akim, Thu Jul 25 17:30:44 2002 UTC revision 1.71 by akim, Thu Jul 25 21:21:02 2002 UTC
# Line 111  useless_nonterminals (void) Line 111  useless_nonterminals (void)
111    while (1)    while (1)
112      {      {
113        bitset_copy (Np, N);        bitset_copy (Np, N);
114        for (r = 1; r < nrules + 1; r++)        for (r = 0; r < nrules; r++)
115          if (!bitset_test (P, r)          if (!bitset_test (P, r)
116              && useful_production (r, N))              && useful_production (r, N))
117            {            {
# Line 158  inaccessable_symbols (void) Line 158  inaccessable_symbols (void)
158       user can know.  */       user can know.  */
159    
160    Vp = bitset_create (nsyms, BITSET_FIXED);    Vp = bitset_create (nsyms, BITSET_FIXED);
161    Pp = bitset_create (nrules + 1, BITSET_FIXED);    Pp = bitset_create (nrules, BITSET_FIXED);
162    
163    /* If the start symbol isn't useful, then nothing will be useful. */    /* If the start symbol isn't useful, then nothing will be useful. */
164    if (bitset_test (N, axiom->number - ntokens))    if (bitset_test (N, axiom->number - ntokens))
# Line 169  inaccessable_symbols (void) Line 169  inaccessable_symbols (void)
169          {          {
170            rule_number_t r;            rule_number_t r;
171            bitset_copy (Vp, V);            bitset_copy (Vp, V);
172            for (r = 1; r < nrules + 1; r++)            for (r = 0; r < nrules; r++)
173              {              {
174                if (!bitset_test (Pp, r)                if (!bitset_test (Pp, r)
175                    && bitset_test (P, r)                    && bitset_test (P, r)
# Line 215  inaccessable_symbols (void) Line 215  inaccessable_symbols (void)
215    
216    /* A token that was used in %prec should not be warned about.  */    /* A token that was used in %prec should not be warned about.  */
217    {    {
218      rule_number_t i;      rule_number_t r;
219      for (i = 1; i < nrules + 1; i++)      for (r = 0; r < nrules; ++r)
220        if (rules[i].precsym != 0)        if (rules[r].precsym != 0)
221          bitset_set (V1, rules[i].precsym->number);          bitset_set (V1, rules[r].precsym->number);
222    }    }
223  }  }
224    
# Line 234  reduce_grammar_tables (void) Line 234  reduce_grammar_tables (void)
234    /* Report and flag useless productions.  */    /* Report and flag useless productions.  */
235    {    {
236      rule_number_t r;      rule_number_t r;
237      for (r = 1; r < nrules + 1; r++)      for (r = 0; r < nrules; r++)
238        {        {
239          rules[r].useful = bitset_test (P, r);          rules[r].useful = bitset_test (P, r);
240          if (!rules[r].useful)          if (!rules[r].useful)
# Line 249  reduce_grammar_tables (void) Line 249  reduce_grammar_tables (void)
249    /* Map the nonterminals to their new index: useful first, useless    /* Map the nonterminals to their new index: useful first, useless
250       afterwards.  Kept for later report.  */       afterwards.  Kept for later report.  */
251    {    {
252      int useful = 1;      int useful = 0;
253      int useless = nrules + 1 - nuseless_productions;      int useless = nrules - nuseless_productions;
254      rule_t *rules_sorted = XMALLOC (rule_t, nrules + 1) - 1;      rule_t *rules_sorted = XMALLOC (rule_t, nrules);
255      rule_number_t r;      rule_number_t r;
256      for (r = 1; r < nrules + 1; ++r)      for (r = 0; r < nrules; ++r)
257        rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r];        rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r];
258      free (rules + 1);      free (rules);
259      rules = rules_sorted;      rules = rules_sorted;
260    
261      /* Renumber the rules markers in RITEMS.  */      /* Renumber the rules markers in RITEMS.  */
262      for (r = 1; r < nrules + 1; ++r)      for (r = 0; r < nrules; ++r)
263        {        {
264          item_number_t *rhsp = rules[r].rhs;          item_number_t *rhsp = rules[r].rhs;
265          for (/* Nothing. */; *rhsp >= 0; ++rhsp)          for (/* Nothing. */; *rhsp >= 0; ++rhsp)
# Line 274  reduce_grammar_tables (void) Line 274  reduce_grammar_tables (void)
274    {    {
275      int r;      int r;
276      int length;      int length;
277      for (r = nrules + 1; r < nrules + 1 + nuseless_productions; ++r)      for (r = nrules; r < nrules + nuseless_productions; ++r)
278        {        {
279          length = rule_rhs_length (&rules[r]);          length = rule_rhs_length (&rules[r]);
280          nritems -= length + 1;          nritems -= length + 1;
# Line 326  nonterminals_reduce (void) Line 326  nonterminals_reduce (void)
326    
327    {    {
328      rule_number_t r;      rule_number_t r;
329      for (r = 1; r < nrules + 1; ++r)      for (r = 0; r < nrules; ++r)
330        {        {
331          item_number_t *rhsp;          item_number_t *rhsp;
332          for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)          for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
# Line 376  reduce_output (FILE *out) Line 376  reduce_output (FILE *out)
376    
377    if (nuseless_productions > 0)    if (nuseless_productions > 0)
378      grammar_rules_partial_print (out, _("Useless rules"),      grammar_rules_partial_print (out, _("Useless rules"),
379                                   nrules + 1,                                   nrules,
380                                   nuseless_productions + nrules + 1);                                   nrules + nuseless_productions);
381  }  }
382    
383    
# Line 425  reduce_grammar (void) Line 425  reduce_grammar (void)
425    /* Allocate the global sets used to compute the reduced grammar */    /* Allocate the global sets used to compute the reduced grammar */
426    
427    N = bitset_create (nvars, BITSET_FIXED);    N = bitset_create (nvars, BITSET_FIXED);
428    P =  bitset_create (nrules + 1, BITSET_FIXED);    P =  bitset_create (nrules, BITSET_FIXED);
429    V = bitset_create (nsyms, BITSET_FIXED);    V = bitset_create (nsyms, BITSET_FIXED);
430    V1 = bitset_create (nsyms, BITSET_FIXED);    V1 = bitset_create (nsyms, BITSET_FIXED);
431    

Legend:
Removed from v.1.70  
changed lines
  Added in v.1.71

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