1 /* $Id: verbose.c,v 1.10 2012/05/26 00:45:17 tom Exp $ */
5 static void log_conflicts(void);
6 static void log_unused(void);
7 static void print_actions(int stateno);
8 static void print_conflicts(int state);
9 static void print_core(int state);
10 static void print_gotos(int stateno);
11 static void print_nulls(int state);
12 static void print_shifts(action *p);
13 static void print_state(int state);
14 static void print_reductions(action *p, int defred2);
16 static short *null_rules;
26 null_rules = TMALLOC(short, nrules);
29 fprintf(verbose_file, "\f\n");
30 for (i = 0; i < nstates; i++)
36 if (SRtotal || RRtotal)
39 fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
41 fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates);
50 fprintf(verbose_file, "\n\nRules never reduced:\n");
51 for (i = 3; i < nrules; ++i)
55 fprintf(verbose_file, "\t%s :", symbol_name[rlhs[i]]);
56 for (p = ritem + rrhs[i]; *p >= 0; ++p)
57 fprintf(verbose_file, " %s", symbol_name[*p]);
58 fprintf(verbose_file, " (%d)\n", i - 2);
68 fprintf(verbose_file, "\n\n");
69 for (i = 0; i < nstates; i++)
71 if (SRconflicts[i] || RRconflicts[i])
73 fprintf(verbose_file, "State %d contains ", i);
74 if (SRconflicts[i] > 0)
75 fprintf(verbose_file, "%d shift/reduce conflict%s",
77 PLURAL(SRconflicts[i]));
78 if (SRconflicts[i] && RRconflicts[i])
79 fprintf(verbose_file, ", ");
80 if (RRconflicts[i] > 0)
81 fprintf(verbose_file, "%d reduce/reduce conflict%s",
83 PLURAL(RRconflicts[i]));
84 fprintf(verbose_file, ".\n");
90 print_state(int state)
93 fprintf(verbose_file, "\n\n");
94 if (SRconflicts[state] || RRconflicts[state])
95 print_conflicts(state);
96 fprintf(verbose_file, "state %d\n", state);
103 print_conflicts(int state)
105 int symbol, act, number;
108 act = 0; /* not shift/reduce... */
111 for (p = parser[state]; p; p = p->next)
113 if (p->suppressed == 2)
116 if (p->symbol != symbol)
120 if (p->action_code == SHIFT)
125 else if (p->suppressed == 1)
127 if (state == final_state && symbol == 0)
129 fprintf(verbose_file, "%d: shift/reduce conflict \
130 (accept, reduce %d) on $end\n", state, p->number - 2);
136 fprintf(verbose_file, "%d: shift/reduce conflict \
137 (shift %d, reduce %d) on %s\n", state, number, p->number - 2,
138 symbol_name[symbol]);
142 fprintf(verbose_file, "%d: reduce/reduce conflict \
143 (reduce %d, reduce %d) on %s\n", state, number - 2, p->number - 2,
144 symbol_name[symbol]);
152 print_core(int state)
161 statep = state_table[state];
164 for (i = 0; i < k; i++)
166 sp1 = sp = ritem + statep->items[i];
171 fprintf(verbose_file, "\t%s : ", symbol_name[rlhs[rule]]);
173 for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
174 fprintf(verbose_file, "%s ", symbol_name[*sp]);
176 putc('.', verbose_file);
180 fprintf(verbose_file, " %s", symbol_name[*sp]);
183 fprintf(verbose_file, " (%d)\n", -2 - *sp);
188 print_nulls(int state)
191 Value_t i, j, k, nnulls;
194 for (p = parser[state]; p; p = p->next)
196 if (p->action_code == REDUCE &&
197 (p->suppressed == 0 || p->suppressed == 1))
200 if (rrhs[i] + 1 == rrhs[i + 1])
202 for (j = 0; j < nnulls && i > null_rules[j]; ++j)
210 else if (i != null_rules[j])
213 for (k = (Value_t) (nnulls - 1); k > j; --k)
214 null_rules[k] = null_rules[k - 1];
221 for (i = 0; i < nnulls; ++i)
224 fprintf(verbose_file, "\t%s : . (%d)\n", symbol_name[rlhs[j]],
227 fprintf(verbose_file, "\n");
231 print_actions(int stateno)
237 if (stateno == final_state)
238 fprintf(verbose_file, "\t$end accept\n");
244 print_reductions(p, defred[stateno]);
247 sp = shift_table[stateno];
248 if (sp && sp->nshifts > 0)
250 as = accessing_symbol[sp->shift[sp->nshifts - 1]];
252 print_gotos(stateno);
257 print_shifts(action *p)
263 for (q = p; q; q = q->next)
265 if (q->suppressed < 2 && q->action_code == SHIFT)
271 for (; p; p = p->next)
273 if (p->action_code == SHIFT && p->suppressed == 0)
274 fprintf(verbose_file, "\t%s shift %d\n",
275 symbol_name[p->symbol], p->number);
281 print_reductions(action *p, int defred2)
287 for (q = p; q; q = q->next)
289 if (q->action_code == REDUCE && q->suppressed < 2)
297 fprintf(verbose_file, "\t. error\n");
300 for (; p; p = p->next)
302 if (p->action_code == REDUCE && p->number != defred2)
305 if (p->suppressed == 0)
306 fprintf(verbose_file, "\t%s reduce %d\n",
307 symbol_name[p->symbol], k);
312 fprintf(verbose_file, "\t. reduce %d\n", defred2 - 2);
317 print_gotos(int stateno)
324 putc('\n', verbose_file);
325 sp = shift_table[stateno];
326 to_state2 = sp->shift;
327 for (i = 0; i < sp->nshifts; ++i)
330 as = accessing_symbol[k];
332 fprintf(verbose_file, "\t%s goto %d\n", symbol_name[as], k);