1 |
/* Find and resolve or report look-ahead conflicts for bison, |
/* Find and resolve or report look-ahead conflicts for bison, |
2 |
Copyright 1984, 1989, 1992, 2000, 2001 Free Software Foundation, Inc. |
Copyright 1984, 1989, 1992, 2000, 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of Bison, the GNU Compiler Compiler. |
This file is part of Bison, the GNU Compiler Compiler. |
5 |
|
|
19 |
02111-1307, USA. */ |
02111-1307, USA. */ |
20 |
|
|
21 |
#include "system.h" |
#include "system.h" |
22 |
|
#include "bitset.h" |
23 |
#include "complain.h" |
#include "complain.h" |
24 |
#include "getargs.h" |
#include "getargs.h" |
25 |
#include "symtab.h" |
#include "symtab.h" |
79 |
static void |
static void |
80 |
flush_reduce (int lookahead, int token) |
flush_reduce (int lookahead, int token) |
81 |
{ |
{ |
82 |
RESETBIT (LA (lookahead), token); |
bitset_reset (LA[lookahead], token); |
83 |
} |
} |
84 |
|
|
85 |
|
|
100 |
errp->nerrs = 0; |
errp->nerrs = 0; |
101 |
|
|
102 |
for (i = 0; i < ntokens; i++) |
for (i = 0; i < ntokens; i++) |
103 |
if (BITISSET (LA (lookahead), i) |
if (bitset_test (LA[lookahead], i) |
104 |
&& BITISSET (lookaheadset, i) |
&& BITISSET (lookaheadset, i) |
105 |
&& symbols[i]->prec) |
&& symbols[i]->prec) |
106 |
{ |
{ |
174 |
precedence */ |
precedence */ |
175 |
for (i = 0; i < state->nlookaheads; ++i) |
for (i = 0; i < state->nlookaheads; ++i) |
176 |
if (rules[LAruleno[state->lookaheadsp + i]].prec) |
if (rules[LAruleno[state->lookaheadsp + i]].prec) |
177 |
for (j = 0; j < tokensetsize; ++j) |
for (j = 0; j < ntokens; ++j) |
178 |
if (LA (state->lookaheadsp + i)[j] & lookaheadset[j]) |
if (bitset_test (LA[state->lookaheadsp + i], j) |
179 |
|
&& BITISSET (lookaheadset, j)) |
180 |
{ |
{ |
181 |
resolve_sr_conflict (state, state->lookaheadsp + i); |
resolve_sr_conflict (state, state->lookaheadsp + i); |
182 |
break; |
break; |
187 |
for conflicts not resolved above. */ |
for conflicts not resolved above. */ |
188 |
for (i = 0; i < state->nlookaheads; ++i) |
for (i = 0; i < state->nlookaheads; ++i) |
189 |
{ |
{ |
190 |
for (j = 0; j < tokensetsize; ++j) |
for (j = 0; j < ntokens; ++j) |
191 |
if (LA (state->lookaheadsp + i)[j] & lookaheadset[j]) |
if (bitset_test (LA[state->lookaheadsp + i], j) |
192 |
|
&& BITISSET (lookaheadset, j)) |
193 |
conflicts[state->number] = 1; |
conflicts[state->number] = 1; |
194 |
|
|
195 |
for (j = 0; j < tokensetsize; ++j) |
for (j = 0; j < ntokens; ++j) |
196 |
lookaheadset[j] |= LA (state->lookaheadsp + i)[j]; |
if (bitset_test (LA[state->lookaheadsp + i], j)) |
197 |
|
SETBIT (lookaheadset, j); |
198 |
} |
} |
199 |
} |
} |
200 |
|
|
201 |
void |
void |
202 |
solve_conflicts (void) |
solve_conflicts (void) |
203 |
{ |
{ |
204 |
int i; |
size_t i; |
205 |
|
|
206 |
conflicts = XCALLOC (char, nstates); |
conflicts = XCALLOC (char, nstates); |
207 |
shiftset = XCALLOC (unsigned, tokensetsize); |
shiftset = XCALLOC (unsigned, tokensetsize); |
237 |
SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); |
SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); |
238 |
|
|
239 |
for (i = 0; i < state->nlookaheads; ++i) |
for (i = 0; i < state->nlookaheads; ++i) |
240 |
for (k = 0; k < tokensetsize; ++k) |
for (k = 0; k < ntokens; ++k) |
241 |
lookaheadset[k] |= LA (state->lookaheadsp + i)[k]; |
if (bitset_test (LA[state->lookaheadsp + i], k)) |
242 |
|
SETBIT (lookaheadset, k); |
243 |
|
|
244 |
for (k = 0; k < tokensetsize; ++k) |
for (k = 0; k < tokensetsize; ++k) |
245 |
lookaheadset[k] &= shiftset[k]; |
lookaheadset[k] &= shiftset[k]; |
270 |
int count = 0; |
int count = 0; |
271 |
int j; |
int j; |
272 |
for (j = 0; j < state->nlookaheads; ++j) |
for (j = 0; j < state->nlookaheads; ++j) |
273 |
if (BITISSET (LA (state->lookaheadsp + j), i)) |
if (bitset_test (LA[state->lookaheadsp + j], i)) |
274 |
count++; |
count++; |
275 |
|
|
276 |
if (count >= 2) |
if (count >= 2) |
327 |
conflicts_output (FILE *out) |
conflicts_output (FILE *out) |
328 |
{ |
{ |
329 |
bool printed_sth = FALSE; |
bool printed_sth = FALSE; |
330 |
int i; |
size_t i; |
331 |
for (i = 0; i < nstates; i++) |
for (i = 0; i < nstates; i++) |
332 |
if (conflicts[i]) |
if (conflicts[i]) |
333 |
{ |
{ |
348 |
void |
void |
349 |
conflicts_print (void) |
conflicts_print (void) |
350 |
{ |
{ |
351 |
int i; |
size_t i; |
352 |
|
|
353 |
/* Is the number of SR conflicts OK? Either EXPECTED_CONFLICTS is |
/* Is the number of SR conflicts OK? Either EXPECTED_CONFLICTS is |
354 |
not set, and then we want 0 SR, or else it is specified, in which |
not set, and then we want 0 SR, or else it is specified, in which |