175 |
`------------------------------------------------------------------*/ |
`------------------------------------------------------------------*/ |
176 |
|
|
177 |
static void |
static void |
178 |
resolve_sr_conflict (state_t *state, int lookahead, |
resolve_sr_conflict (state_t *state, int ruleno, |
179 |
symbol_t **errs) |
symbol_t **errs) |
180 |
{ |
{ |
181 |
symbol_number_t i; |
symbol_number_t i; |
182 |
|
reductions_t *reds = state->reductions; |
183 |
/* Find the rule to reduce by to get precedence of reduction. */ |
/* Find the rule to reduce by to get precedence of reduction. */ |
184 |
rule_t *redrule = state->lookaheads_rule[lookahead]; |
rule_t *redrule = reds->rules[ruleno]; |
185 |
int redprec = redrule->prec->prec; |
int redprec = redrule->prec->prec; |
186 |
bitset lookaheads = state->lookaheads[lookahead]; |
bitset lookaheads = reds->lookaheads[ruleno]; |
187 |
int nerrs = 0; |
int nerrs = 0; |
188 |
|
|
189 |
for (i = 0; i < ntokens; i++) |
for (i = 0; i < ntokens; i++) |
260 |
{ |
{ |
261 |
int i; |
int i; |
262 |
transitions_t *transitions = state->transitions; |
transitions_t *transitions = state->transitions; |
263 |
|
reductions_t *reds = state->reductions; |
264 |
|
|
265 |
if (state->consistent) |
if (state->consistent) |
266 |
return; |
return; |
273 |
/* Loop over all rules which require lookahead in this state. First |
/* Loop over all rules which require lookahead in this state. First |
274 |
check for shift-reduce conflict, and try to resolve using |
check for shift-reduce conflict, and try to resolve using |
275 |
precedence. */ |
precedence. */ |
276 |
for (i = 0; i < state->nlookaheads; ++i) |
for (i = 0; i < reds->num; ++i) |
277 |
if (state->lookaheads_rule[i]->prec |
if (reds->rules[i]->prec && reds->rules[i]->prec->prec |
278 |
&& state->lookaheads_rule[i]->prec->prec |
&& !bitset_disjoint_p (reds->lookaheads[i], lookaheadset)) |
|
&& !bitset_disjoint_p (state->lookaheads[i], lookaheadset)) |
|
279 |
{ |
{ |
280 |
resolve_sr_conflict (state, i, errs); |
resolve_sr_conflict (state, i, errs); |
281 |
break; |
break; |
283 |
|
|
284 |
/* Loop over all rules which require lookahead in this state. Check |
/* Loop over all rules which require lookahead in this state. Check |
285 |
for conflicts not resolved above. */ |
for conflicts not resolved above. */ |
286 |
for (i = 0; i < state->nlookaheads; ++i) |
for (i = 0; i < reds->num; ++i) |
287 |
{ |
{ |
288 |
if (!bitset_disjoint_p (state->lookaheads[i], lookaheadset)) |
if (!bitset_disjoint_p (reds->lookaheads[i], lookaheadset)) |
289 |
conflicts[state->number] = 1; |
conflicts[state->number] = 1; |
290 |
|
|
291 |
bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]); |
bitset_or (lookaheadset, lookaheadset, reds->lookaheads[i]); |
292 |
} |
} |
293 |
} |
} |
294 |
|
|
334 |
int i; |
int i; |
335 |
int src_count = 0; |
int src_count = 0; |
336 |
transitions_t *transitions = state->transitions; |
transitions_t *transitions = state->transitions; |
337 |
|
reductions_t *reds = state->reductions; |
338 |
|
|
339 |
if (!transitions) |
if (!transitions) |
340 |
return 0; |
return 0; |
345 |
FOR_EACH_SHIFT (transitions, i) |
FOR_EACH_SHIFT (transitions, i) |
346 |
bitset_set (shiftset, TRANSITION_SYMBOL (transitions, i)); |
bitset_set (shiftset, TRANSITION_SYMBOL (transitions, i)); |
347 |
|
|
348 |
for (i = 0; i < state->nlookaheads; ++i) |
for (i = 0; i < reds->num; ++i) |
349 |
bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]); |
bitset_or (lookaheadset, lookaheadset, reds->lookaheads[i]); |
350 |
|
|
351 |
bitset_and (lookaheadset, lookaheadset, shiftset); |
bitset_and (lookaheadset, lookaheadset, shiftset); |
352 |
|
|
367 |
count_rr_conflicts (state_t *state, int one_per_token) |
count_rr_conflicts (state_t *state, int one_per_token) |
368 |
{ |
{ |
369 |
int i; |
int i; |
370 |
|
reductions_t *reds = state->reductions; |
371 |
int rrc_count = 0; |
int rrc_count = 0; |
372 |
|
|
|
if (state->nlookaheads < 2) |
|
|
return 0; |
|
|
|
|
373 |
for (i = 0; i < ntokens; i++) |
for (i = 0; i < ntokens; i++) |
374 |
{ |
{ |
375 |
int count = 0; |
int count = 0; |
376 |
int j; |
int j; |
377 |
for (j = 0; j < state->nlookaheads; ++j) |
for (j = 0; j < reds->num; ++j) |
378 |
if (bitset_test (state->lookaheads[j], i)) |
if (bitset_test (reds->lookaheads[j], i)) |
379 |
count++; |
count++; |
380 |
|
|
381 |
if (count >= 2) |
if (count >= 2) |
456 |
for (i = 0; i < nstates; i++) |
for (i = 0; i < nstates; i++) |
457 |
{ |
{ |
458 |
state_t *s = states[i]; |
state_t *s = states[i]; |
459 |
|
reductions_t *reds = s->reductions; |
460 |
int j; |
int j; |
461 |
for (j = 0; j < s->reductions->num; ++j) |
for (j = 0; j < reds->num; ++j) |
462 |
used_rules[s->reductions->rules[j]->number] = TRUE; |
used_rules[reds->rules[j]->number] = TRUE; |
463 |
if (conflicts[i]) |
if (conflicts[i]) |
464 |
{ |
{ |
465 |
fprintf (out, _("State %d contains "), i); |
fprintf (out, _("State %d contains "), i); |