]>
git.saurik.com Git - bison.git/blob - src/print.c
ff6803d431494aea8970ebd60a3826959550df1f
1 /* Print information on generated parser, for bison,
2 Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
33 extern short *accessing_symbol
;
34 extern core
**state_table
;
35 extern shifts
**shift_table
;
36 extern errs
**err_table
;
37 extern reductions
**reduction_table
;
38 extern char *consistent
;
39 extern char any_conflicts
;
40 extern char *conflicts
;
41 extern int final_state
;
43 extern void conflict_log
PARAMS((void));
44 extern void verbose_conflict_log
PARAMS((void));
45 extern void print_reductions
PARAMS((int));
47 extern void terse
PARAMS((void));
48 extern void verbose
PARAMS((void));
50 #if 0 /* XXX currently unused. */
51 static void print_token
PARAMS((int, int));
54 static void print_state
PARAMS((int));
55 static void print_core
PARAMS((int));
56 static void print_actions
PARAMS((int));
57 static void print_grammar
PARAMS((void));
75 verbose_conflict_log();
79 for (i
= 0; i
< nstates
; i
++)
86 #if 0 /* XXX currently unused. */
88 print_token (int extnum
, int token
)
90 fprintf(foutput
, _(" type %d is %s\n"), extnum
, tags
[token
]);
96 print_state (int state
)
98 fprintf(foutput
, _("\n\nstate %d\n\n"), state
);
100 print_actions(state
);
105 print_core (int state
)
110 register core
*statep
;
114 statep
= state_table
[state
];
119 for (i
= 0; i
< k
; i
++)
121 sp1
= sp
= ritem
+ statep
->items
[i
];
127 fprintf(foutput
, " %s -> ", tags
[rlhs
[rule
]]);
129 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
131 fprintf(foutput
, "%s ", tags
[*sp
]);
138 fprintf(foutput
, " %s", tags
[*sp
]);
142 fprintf (foutput
, _(" (rule %d)"), rule
);
151 print_actions (int state
)
157 register shifts
*shiftp
;
159 register reductions
*redp
;
162 shiftp
= shift_table
[state
];
163 redp
= reduction_table
[state
];
164 errp
= err_table
[state
];
166 if (!shiftp
&& !redp
)
168 if (final_state
== state
)
169 fprintf(foutput
, _(" $default\taccept\n"));
171 fprintf(foutput
, _(" NO ACTIONS\n"));
179 for (i
= 0; i
< k
; i
++)
181 if (! shiftp
->shifts
[i
]) continue;
182 state1
= shiftp
->shifts
[i
];
183 symbol
= accessing_symbol
[state1
];
184 /* The following line used to be turned off. */
185 if (ISVAR(symbol
)) break;
186 if (symbol
==0) /* I.e. strcmp(tags[symbol],"$")==0 */
187 fprintf(foutput
, _(" $ \tgo to state %d\n"), state1
);
189 fprintf(foutput
, _(" %-4s\tshift, and go to state %d\n"),
190 tags
[symbol
], state1
);
208 for (j
= 0; j
< nerrs
; j
++)
210 if (! errp
->errs
[j
]) continue;
211 symbol
= errp
->errs
[j
];
212 fprintf(foutput
, _(" %-4s\terror (nonassociative)\n"), tags
[symbol
]);
219 if (consistent
[state
] && redp
)
221 rule
= redp
->rules
[0];
223 fprintf(foutput
, _(" $default\treduce using rule %d (%s)\n\n"),
228 print_reductions(state
);
235 if (! shiftp
->shifts
[i
]) continue;
236 state1
= shiftp
->shifts
[i
];
237 symbol
= accessing_symbol
[state1
];
238 fprintf(foutput
, _(" %-4s\tgo to state %d\n"), tags
[symbol
], state1
);
245 #define END_TEST(end) \
247 if (column + strlen(buffer) > (end)) { \
248 fprintf (foutput, "%s\n ", buffer); \
262 /* rule # : LHS -> RHS */
263 fputs(_("\nGrammar\n"), foutput
);
264 for (i
= 1; i
<= nrules
; i
++)
265 /* Don't print rules disabled in reduce_grammar_tables. */
268 fprintf(foutput
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
269 rule
= &ritem
[rrhs
[i
]];
272 fprintf(foutput
, " %s", tags
[*rule
++]);
274 fputs (_(" /* empty */"), foutput
);
278 /* TERMINAL (type #) : rule #s terminal is on RHS */
279 fputs(_("\nTerminals, with rules where they appear\n\n"), foutput
);
280 fprintf(foutput
, "%s (-1)\n", tags
[0]);
283 for (i
= 0; i
<= max_user_token_number
; i
++)
284 if (token_translations
[i
] != 2)
287 column
= strlen (tags
[token_translations
[i
]]);
288 fprintf(foutput
, "%s", tags
[token_translations
[i
]]);
290 sprintf (buffer
, " (%d)", i
);
292 for (j
= 1; j
<= nrules
; j
++)
294 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
295 if (*rule
== token_translations
[i
])
298 sprintf (buffer
+ strlen(buffer
), " %d", j
);
302 fprintf (foutput
, "%s\n", buffer
);
306 for (i
= 1; i
< ntokens
; i
++)
309 column
= strlen (tags
[i
]);
310 fprintf(foutput
, "%s", tags
[i
]);
312 sprintf (buffer
, " (%d)", i
);
314 for (j
= 1; j
<= nrules
; j
++)
316 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
320 sprintf (buffer
+ strlen(buffer
), " %d", j
);
324 fprintf (foutput
, "%s\n", buffer
);
327 fputs(_("\nNonterminals, with rules where they appear\n\n"), foutput
);
328 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
330 int left_count
= 0, right_count
= 0;
332 for (j
= 1; j
<= nrules
; j
++)
336 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
345 fprintf(foutput
, "%s", tags
[i
]);
346 column
= strlen (tags
[i
]);
347 sprintf (buffer
, " (%d)", i
);
353 sprintf (buffer
+ strlen(buffer
), _(" on left:"));
355 for (j
= 1; j
<= nrules
; j
++)
359 sprintf (buffer
+ strlen(buffer
), " %d", j
);
366 sprintf (buffer
+ strlen(buffer
), ",");
368 sprintf (buffer
+ strlen(buffer
), _(" on right:"));
369 for (j
= 1; j
<= nrules
; j
++)
371 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
375 sprintf (buffer
+ strlen(buffer
), " %d", j
);
380 fprintf (foutput
, "%s\n", buffer
);