fix conflict pretty-printing

This commit is contained in:
Sven M. Hallberg 2013-06-19 18:21:53 +02:00
parent 55c9a3d9c5
commit ecfc0a8e62

View file

@ -425,9 +425,11 @@ void h_pprint_lrdfa(FILE *f, const HCFGrammar *g,
void pprint_lraction(FILE *f, const HCFGrammar *g, const HLRAction *action) void pprint_lraction(FILE *f, const HCFGrammar *g, const HLRAction *action)
{ {
if(action->type == HLR_SHIFT) { switch(action->type) {
case HLR_SHIFT:
fprintf(f, "s%lu", action->nextstate); fprintf(f, "s%lu", action->nextstate);
} else { break;
case HLR_REDUCE:
fputs("r(", f); fputs("r(", f);
h_pprint_symbol(f, g, action->production.lhs); h_pprint_symbol(f, g, action->production.lhs);
fputs(" -> ", f); fputs(" -> ", f);
@ -439,6 +441,18 @@ void pprint_lraction(FILE *f, const HCFGrammar *g, const HLRAction *action)
h_pprint_sequence(f, g, &seq); h_pprint_sequence(f, g, &seq);
#endif #endif
fputc(')', f); fputc(')', f);
break;
case HLR_CONFLICT:
fputc('!', f);
for(HSlistNode *x=action->branches->head; x; x=x->next) {
HLRAction *branch = x->elem;
assert(branch->type != HLR_CONFLICT); // no nesting
pprint_lraction(f, g, branch);
if(x->next) fputc('/', f); // separator
}
break;
default:
assert_message(0, "not reached");
} }
} }
@ -459,13 +473,7 @@ void h_pprint_lrtable(FILE *f, const HCFGrammar *g, const HLRTable *table,
fputc(' ', f); // separator fputc(' ', f); // separator
h_pprint_symbol(f, g, symbol); h_pprint_symbol(f, g, symbol);
fputc(':', f); fputc(':', f);
if(table->forall[i]) { pprint_lraction(f, g, action);
fputc(action->type == HLR_SHIFT? 's' : 'r', f);
fputc('/', f);
fputc(table->forall[i]->type == HLR_SHIFT? 's' : 'r', f);
} else {
pprint_lraction(f, g, action);
}
H_END_FOREACH H_END_FOREACH
fputc('\n', f); fputc('\n', f);
} }