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

Diff of /bison/src/conflicts.c

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

revision 1.88 by akim, Sun Jun 30 17:34:31 2002 UTC revision 1.89 by akim, Wed Jul 3 06:51:43 2002 UTC
# Line 139  log_resolution (rule_t *rule, symbol_num Line 139  log_resolution (rule_t *rule, symbol_num
139  static void  static void
140  flush_shift (state_t *state, int token)  flush_shift (state_t *state, int token)
141  {  {
142    transitions_t *transitions = state->shifts;    transitions_t *transitions = state->transitions;
143    int i;    int i;
144    
145    bitset_reset (lookaheadset, token);    bitset_reset (lookaheadset, token);
# Line 170  flush_reduce (bitset lookaheads, int tok Line 170  flush_reduce (bitset lookaheads, int tok
170  | shift or reduce tables so that there is no longer a conflict.     |  | shift or reduce tables so that there is no longer a conflict.     |
171  |                                                                   |  |                                                                   |
172  | LOOKAHEAD is the number of the lookahead bitset to consider.      |  | LOOKAHEAD is the number of the lookahead bitset to consider.      |
173    |                                                                   |
174    | ERRS can be used to store discovered explicit errors.             |
175  `------------------------------------------------------------------*/  `------------------------------------------------------------------*/
176    
177  static void  static void
178  resolve_sr_conflict (state_t *state, int lookahead)  resolve_sr_conflict (state_t *state, int lookahead,
179                         symbol_number_t *errs)
180  {  {
181    symbol_number_t i;    symbol_number_t i;
182    /* Find the rule to reduce by to get precedence of reduction.  */    /* Find the rule to reduce by to get precedence of reduction.  */
183    rule_t *redrule = state->lookaheads_rule[lookahead];    rule_t *redrule = state->lookaheads_rule[lookahead];
184    int redprec = redrule->prec->prec;    int redprec = redrule->prec->prec;
185    bitset lookaheads = state->lookaheads[lookahead];    bitset lookaheads = state->lookaheads[lookahead];
186    errs_t *errp = errs_new (ntokens + 1);    int nerrs = 0;
   errp->num = 0;  
187    
188    for (i = 0; i < ntokens; i++)    for (i = 0; i < ntokens; i++)
189      if (bitset_test (lookaheads, i)      if (bitset_test (lookaheads, i)
# Line 224  resolve_sr_conflict (state_t *state, int Line 226  resolve_sr_conflict (state_t *state, int
226                flush_shift (state, i);                flush_shift (state, i);
227                flush_reduce (lookaheads, i);                flush_reduce (lookaheads, i);
228                /* Record an explicit error for this token.  */                /* Record an explicit error for this token.  */
229                errp->symbols[errp->num++] = i;                errs[nerrs++] = i;
230                break;                break;
231    
232              case undef_assoc:              case undef_assoc:
# Line 235  resolve_sr_conflict (state_t *state, int Line 237  resolve_sr_conflict (state_t *state, int
237    
238    /* Some tokens have been explicitly made errors.  Allocate a    /* Some tokens have been explicitly made errors.  Allocate a
239       permanent errs structure for this state, to record them.  */       permanent errs structure for this state, to record them.  */
240    state->errs = errs_dup (errp);    state_errs_set (state, nerrs, errs);
   free (errp);  
241    
242    if (obstack_object_size (&solved_conflicts_obstack))    if (obstack_object_size (&solved_conflicts_obstack))
243      {      {
# Line 246  resolve_sr_conflict (state_t *state, int Line 247  resolve_sr_conflict (state_t *state, int
247  }  }
248    
249    
250    /*-------------------------------------------------------------------.
251    | Solve the S/R conflicts of STATE using the                         |
252    | precedence/associativity, and flag it inconsistent if it still has |
253    | conflicts.  ERRS can be used as storage to compute the list of     |
254    | lookaheads on which this STATE raises a parse error (%nonassoc).   |
255    `-------------------------------------------------------------------*/
256    
257  static void  static void
258  set_conflicts (state_t *state)  set_conflicts (state_t *state, symbol_number_t *errs)
259  {  {
260    int i;    int i;
261    transitions_t *transitions;    transitions_t *transitions = state->transitions;
262    
263    if (state->consistent)    if (state->consistent)
264      return;      return;
265    
266    bitset_zero (lookaheadset);    bitset_zero (lookaheadset);
267    
   transitions = state->shifts;  
268    for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)    for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
269      if (!TRANSITION_IS_DISABLED (transitions, i))      if (!TRANSITION_IS_DISABLED (transitions, i))
270        bitset_set (lookaheadset, TRANSITION_SYMBOL (transitions, i));        bitset_set (lookaheadset, TRANSITION_SYMBOL (transitions, i));
# Line 270  set_conflicts (state_t *state) Line 277  set_conflicts (state_t *state)
277          && state->lookaheads_rule[i]->prec->prec          && state->lookaheads_rule[i]->prec->prec
278          && !bitset_disjoint_p (state->lookaheads[i], lookaheadset))          && !bitset_disjoint_p (state->lookaheads[i], lookaheadset))
279        {        {
280          resolve_sr_conflict (state, i);          resolve_sr_conflict (state, i, errs);
281          break;          break;
282        }        }
283    
# Line 285  set_conflicts (state_t *state) Line 292  set_conflicts (state_t *state)
292      }      }
293  }  }
294    
295    
296    /*----------------------------------------------------------------.
297    | Solve all the S/R conflicts using the precedence/associativity, |
298    | and flag as inconsistent the states that still have conflicts.  |
299    `----------------------------------------------------------------*/
300    
301  void  void
302  conflicts_solve (void)  conflicts_solve (void)
303  {  {
304    state_number_t i;    state_number_t i;
305      /* List of lookaheads on which we explicitly raise a parse error.  */
306      symbol_number_t *errs = XMALLOC (symbol_number_t, ntokens + 1);
307    
308    conflicts = XCALLOC (char, nstates);    conflicts = XCALLOC (char, nstates);
309    shiftset = bitset_create (ntokens, BITSET_FIXED);    shiftset = bitset_create (ntokens, BITSET_FIXED);
# Line 296  conflicts_solve (void) Line 311  conflicts_solve (void)
311    obstack_init (&solved_conflicts_obstack);    obstack_init (&solved_conflicts_obstack);
312    
313    for (i = 0; i < nstates; i++)    for (i = 0; i < nstates; i++)
314      set_conflicts (states[i]);      {
315          set_conflicts (states[i], errs);
316    
317          /* For uniformity of the code, make sure all the states have a valid
318             `errs' member.  */
319          if (!states[i]->errs)
320            states[i]->errs = errs_new (0, 0);
321        }
322    
323      free (errs);
324  }  }
325    
326    
# Line 309  count_sr_conflicts (state_t *state) Line 333  count_sr_conflicts (state_t *state)
333  {  {
334    int i;    int i;
335    int src_count = 0;    int src_count = 0;
336    transitions_t *transitions = state->shifts;    transitions_t *transitions = state->transitions;
337    
338    if (!transitions)    if (!transitions)
339      return 0;      return 0;

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

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