/[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.67 by akim, Mon Mar 4 12:03:35 2002 UTC revision 1.68 by akim, Mon Mar 4 12:04:33 2002 UTC
# Line 35  Line 35 
35  int expected_conflicts = -1;  int expected_conflicts = -1;
36  static char *conflicts = NULL;  static char *conflicts = NULL;
37    
38  static unsigned *shiftset = NULL;  static bitset shiftset;
39  static unsigned *lookaheadset = NULL;  static bitset lookaheadset;
40    
41    
42  static inline void  static inline void
# Line 63  flush_shift (state_t *state, int token) Line 63  flush_shift (state_t *state, int token)
63    shifts *shiftp = state->shifts;    shifts *shiftp = state->shifts;
64    int i;    int i;
65    
66    RESETBIT (lookaheadset, token);    bitset_reset (lookaheadset, token);
67    for (i = 0; i < shiftp->nshifts; i++)    for (i = 0; i < shiftp->nshifts; i++)
68      if (!SHIFT_IS_DISABLED (shiftp, i) && SHIFT_SYMBOL (shiftp, i) == token)      if (!SHIFT_IS_DISABLED (shiftp, i) && SHIFT_SYMBOL (shiftp, i) == token)
69        SHIFT_DISABLE (shiftp, i);        SHIFT_DISABLE (shiftp, i);
# Line 101  resolve_sr_conflict (state_t *state, int Line 101  resolve_sr_conflict (state_t *state, int
101    
102    for (i = 0; i < ntokens; i++)    for (i = 0; i < ntokens; i++)
103      if (bitset_test (LA[lookahead], i)      if (bitset_test (LA[lookahead], i)
104          && BITISSET (lookaheadset, i)          && bitset_test (lookaheadset, i)
105          && symbols[i]->prec)          && symbols[i]->prec)
106        {        {
107          /* Shift-reduce conflict occurs for token number i          /* Shift-reduce conflict occurs for token number i
# Line 161  set_conflicts (state_t *state) Line 161  set_conflicts (state_t *state)
161    if (state->consistent)    if (state->consistent)
162      return;      return;
163    
164    for (i = 0; i < tokensetsize; i++)    bitset_zero (lookaheadset);
     lookaheadset[i] = 0;  
165    
166    shiftp = state->shifts;    shiftp = state->shifts;
167    for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)    for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
168      if (!SHIFT_IS_DISABLED (shiftp, i))      if (!SHIFT_IS_DISABLED (shiftp, i))
169        SETBIT (lookaheadset, SHIFT_SYMBOL (shiftp, i));        bitset_set (lookaheadset, SHIFT_SYMBOL (shiftp, i));
170    
171    /* Loop over all rules which require lookahead in this state.  First    /* Loop over all rules which require lookahead in this state.  First
172       check for shift-reduce conflict, and try to resolve using       check for shift-reduce conflict, and try to resolve using
# Line 176  set_conflicts (state_t *state) Line 175  set_conflicts (state_t *state)
175      if (rules[LAruleno[state->lookaheadsp + i]].prec)      if (rules[LAruleno[state->lookaheadsp + i]].prec)
176        for (j = 0; j < ntokens; ++j)        for (j = 0; j < ntokens; ++j)
177          if (bitset_test (LA[state->lookaheadsp + i], j)          if (bitset_test (LA[state->lookaheadsp + i], j)
178              && BITISSET (lookaheadset, j))              && bitset_test (lookaheadset, j))
179            {            {
180              resolve_sr_conflict (state, state->lookaheadsp + i);              resolve_sr_conflict (state, state->lookaheadsp + i);
181              break;              break;
# Line 189  set_conflicts (state_t *state) Line 188  set_conflicts (state_t *state)
188      {      {
189        for (j = 0; j < ntokens; ++j)        for (j = 0; j < ntokens; ++j)
190          if (bitset_test (LA[state->lookaheadsp + i], j)          if (bitset_test (LA[state->lookaheadsp + i], j)
191              && BITISSET (lookaheadset, j))              && bitset_test (lookaheadset, j))
192            conflicts[state->number] = 1;            conflicts[state->number] = 1;
193    
194        for (j = 0; j < ntokens; ++j)        for (j = 0; j < ntokens; ++j)
195          if (bitset_test (LA[state->lookaheadsp + i], j))          if (bitset_test (LA[state->lookaheadsp + i], j))
196            SETBIT (lookaheadset, j);            bitset_set (lookaheadset, j);
197      }      }
198  }  }
199    
# Line 204  solve_conflicts (void) Line 203  solve_conflicts (void)
203    size_t i;    size_t i;
204    
205    conflicts = XCALLOC (char, nstates);    conflicts = XCALLOC (char, nstates);
206    shiftset = XCALLOC (unsigned, tokensetsize);    shiftset = bitset_create (ntokens, BITSET_FIXED);
207    lookaheadset = XCALLOC (unsigned, tokensetsize);    bitset_zero (shiftset);
208      lookaheadset = bitset_create (ntokens, BITSET_FIXED);
209      bitset_zero (lookaheadset);
210    
211    for (i = 0; i < nstates; i++)    for (i = 0; i < nstates; i++)
212      set_conflicts (states[i]);      set_conflicts (states[i]);
# Line 226  count_sr_conflicts (state_t *state) Line 227  count_sr_conflicts (state_t *state)
227    if (!shiftp)    if (!shiftp)
228      return 0;      return 0;
229    
230    for (i = 0; i < tokensetsize; i++)    bitset_zero (lookaheadset);
231      {    bitset_zero (shiftset);
       shiftset[i] = 0;  
       lookaheadset[i] = 0;  
     }  
232    
233    for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)    for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++)
234      if (!SHIFT_IS_DISABLED (shiftp, i))      if (!SHIFT_IS_DISABLED (shiftp, i))
235        SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i));        bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
236    
237    for (i = 0; i < state->nlookaheads; ++i)    for (i = 0; i < state->nlookaheads; ++i)
238      for (k = 0; k < ntokens; ++k)      for (k = 0; k < ntokens; ++k)
239        if (bitset_test (LA[state->lookaheadsp + i], k))        if (bitset_test (LA[state->lookaheadsp + i], k))
240          SETBIT (lookaheadset, k);          bitset_set (lookaheadset, k);
241    
242    for (k = 0; k < tokensetsize; ++k)    bitset_and (lookaheadset, lookaheadset, shiftset);
     lookaheadset[k] &= shiftset[k];  
243    
244    for (i = 0; i < ntokens; i++)    for (i = 0; i < ntokens; i++)
245      if (BITISSET (lookaheadset, i))      if (bitset_test (lookaheadset, i))
246        src_count++;        src_count++;
247    
248    return src_count;    return src_count;
# Line 408  void Line 405  void
405  free_conflicts (void)  free_conflicts (void)
406  {  {
407    XFREE (conflicts);    XFREE (conflicts);
408    XFREE (shiftset);    bitset_free (shiftset);
409    XFREE (lookaheadset);    bitset_free (lookaheadset);
410  }  }

Legend:
Removed from v.1.67  
changed lines
  Added in v.1.68

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