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

Diff of /bison/src/print.c

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

revision 1.87 by akim, Tue Jul 30 11:06:50 2002 UTC revision 1.88 by akim, Thu Aug 1 18:14:30 2002 UTC
# Line 244  state_default_rule (state_t *state) Line 244  state_default_rule (state_t *state)
244          bitset_set (shiftset, errp->symbols[i]->number);          bitset_set (shiftset, errp->symbols[i]->number);
245    }    }
246    
247    for (i = 0; i < state->nlookaheads; ++i)    for (i = 0; i < redp->num; ++i)
248      {      {
249        int count = 0;        int count = 0;
250    
251        /* How many non-masked lookaheads are there for this reduction?        /* How many non-masked lookaheads are there for this reduction?
252           */           */
253        bitset_andn (lookaheadset, state->lookaheads[i], shiftset);        bitset_andn (lookaheadset, redp->lookaheads[i], shiftset);
254        count = bitset_count (lookaheadset);        count = bitset_count (lookaheadset);
255    
256        if (count > cmax)        if (count > cmax)
257          {          {
258            cmax = count;            cmax = count;
259            default_rule = state->lookaheads_rule[i];            default_rule = redp->rules[i];
260          }          }
261    
262        /* 3. And finally, each reduction is possibly masked by previous        /* 3. And finally, each reduction is possibly masked by previous
263           reductions (in R/R conflicts, we keep the first reductions).           reductions (in R/R conflicts, we keep the first reductions).
264           */           */
265        bitset_or (shiftset, shiftset, state->lookaheads[i]);        bitset_or (shiftset, shiftset, redp->lookaheads[i]);
266      }      }
267    
268    return default_rule;    return default_rule;
# Line 322  print_reductions (FILE *out, state_t *st Line 322  print_reductions (FILE *out, state_t *st
322    /* Compute the width of the lookaheads column.  */    /* Compute the width of the lookaheads column.  */
323    if (default_rule)    if (default_rule)
324      width = strlen (_("$default"));      width = strlen (_("$default"));
   for (i = 0; i < ntokens; i++)  
     {  
       int count = bitset_test (shiftset, i);  
325    
326        for (j = 0; j < state->nlookaheads; ++j)    if (redp->lookaheads)
327          if (bitset_test (state->lookaheads[j], i))      for (i = 0; i < ntokens; i++)
328            {        {
329              if (count == 0)          int count = bitset_test (shiftset, i);
330                {  
331                  if (state->lookaheads_rule[j] != default_rule)          for (j = 0; j < redp->num; ++j)
332              if (bitset_test (redp->lookaheads[j], i))
333                {
334                  if (count == 0)
335                    {
336                      if (redp->rules[j] != default_rule)
337                        max_length (&width, symbols[i]->tag);
338                      count++;
339                    }
340                  else
341                    {
342                    max_length (&width, symbols[i]->tag);                    max_length (&width, symbols[i]->tag);
343                  count++;                  }
344                }              }
345              else        }
               {  
                 max_length (&width, symbols[i]->tag);  
               }  
           }  
     }  
346    
347    /* Nothing to report. */    /* Nothing to report. */
348    if (!width)    if (!width)
# Line 350  print_reductions (FILE *out, state_t *st Line 352  print_reductions (FILE *out, state_t *st
352    width += 2;    width += 2;
353    
354    /* Report lookaheads (or $default) and reductions.  */    /* Report lookaheads (or $default) and reductions.  */
355    for (i = 0; i < ntokens; i++)    if (redp->lookaheads)
356      {      for (i = 0; i < ntokens; i++)
357        int defaulted = 0;        {
358        int count = bitset_test (shiftset, i);          int defaulted = 0;
359            int count = bitset_test (shiftset, i);
360        for (j = 0; j < state->nlookaheads; ++j)  
361          if (bitset_test (state->lookaheads[j], i))          for (j = 0; j < redp->num; ++j)
362            {            if (bitset_test (redp->lookaheads[j], i))
363              if (count == 0)              {
364                {                if (count == 0)
365                  if (state->lookaheads_rule[j] != default_rule)                  {
366                      if (redp->rules[j] != default_rule)
367                        print_reduction (out, width,
368                                         symbols[i]->tag,
369                                         redp->rules[j], TRUE);
370                      else
371                        defaulted = 1;
372                      count++;
373                    }
374                  else
375                    {
376                      if (defaulted)
377                        print_reduction (out, width,
378                                         symbols[i]->tag,
379                                         default_rule, TRUE);
380                      defaulted = 0;
381                    print_reduction (out, width,                    print_reduction (out, width,
382                                     symbols[i]->tag,                                     symbols[i]->tag,
383                                     state->lookaheads_rule[j], TRUE);                                     redp->rules[j], FALSE);
384                  else                  }
385                    defaulted = 1;              }
386                  count++;        }
               }  
             else  
               {  
                 if (defaulted)  
                   print_reduction (out, width,  
                                    symbols[i]->tag,  
                                    default_rule, TRUE);  
                 defaulted = 0;  
                 print_reduction (out, width,  
                                  symbols[i]->tag,  
                                  state->lookaheads_rule[j], FALSE);  
               }  
           }  
     }  
387    
388    if (default_rule)    if (default_rule)
389      print_reduction (out, width,      print_reduction (out, width,

Legend:
Removed from v.1.87  
changed lines
  Added in v.1.88

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