]>
git.saurik.com Git - bison.git/blob - src/print.c
8e10e4cfc06ad2fdc414f923156f77660aa1d28e
1 /* Print information on generated parser, for bison,
2 Copyright (C) 1984, 1986, 1989, 2000 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. */
31 extern errs
**err_table
;
32 extern char any_conflicts
;
33 extern char *conflicts
;
34 extern int final_state
;
36 extern void conflict_log
PARAMS ((void));
37 extern void verbose_conflict_log
PARAMS ((void));
38 extern void print_reductions
PARAMS ((int));
40 extern void terse
PARAMS ((void));
41 extern void verbose
PARAMS ((void));
43 #if 0 /* XXX currently unused. */
44 static void print_token
PARAMS ((int, int));
47 static void print_state
PARAMS ((int));
48 static void print_core
PARAMS ((int));
49 static void print_actions
PARAMS ((int));
50 static void print_grammar
PARAMS ((void));
66 verbose_conflict_log ();
70 for (i
= 0; i
< nstates
; i
++)
75 #if 0 /* XXX currently unused. */
77 print_token (int extnum
, int token
)
79 fprintf (foutput
, _(" type %d is %s\n"), extnum
, tags
[token
]);
85 print_state (int state
)
87 fprintf (foutput
, _("\n\nstate %d\n\n"), state
);
89 print_actions (state
);
94 print_core (int state
)
103 statep
= state_table
[state
];
109 for (i
= 0; i
< k
; i
++)
111 sp1
= sp
= ritem
+ statep
->items
[i
];
117 fprintf (foutput
, " %s -> ", tags
[rlhs
[rule
]]);
119 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
121 fprintf (foutput
, "%s ", tags
[*sp
]);
128 fprintf (foutput
, " %s", tags
[*sp
]);
132 fprintf (foutput
, _(" (rule %d)"), rule
);
133 putc ('\n', foutput
);
136 putc ('\n', foutput
);
141 print_actions (int state
)
152 shiftp
= shift_table
[state
];
153 redp
= reduction_table
[state
];
154 errp
= err_table
[state
];
156 if (!shiftp
&& !redp
)
158 if (final_state
== state
)
159 fprintf (foutput
, _(" $default\taccept\n"));
161 fprintf (foutput
, _(" NO ACTIONS\n"));
169 for (i
= 0; i
< k
; i
++)
171 if (!shiftp
->shifts
[i
])
173 state1
= shiftp
->shifts
[i
];
174 symbol
= accessing_symbol
[state1
];
175 /* The following line used to be turned off. */
178 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
179 fprintf (foutput
, _(" $ \tgo to state %d\n"), state1
);
181 fprintf (foutput
, _(" %-4s\tshift, and go to state %d\n"),
182 tags
[symbol
], state1
);
186 putc ('\n', foutput
);
200 for (j
= 0; j
< nerrs
; j
++)
204 symbol
= errp
->errs
[j
];
205 fprintf (foutput
, _(" %-4s\terror (nonassociative)\n"),
210 putc ('\n', foutput
);
213 if (consistent
[state
] && redp
)
215 rule
= redp
->rules
[0];
217 fprintf (foutput
, _(" $default\treduce using rule %d (%s)\n\n"),
222 print_reductions (state
);
229 if (!shiftp
->shifts
[i
])
231 state1
= shiftp
->shifts
[i
];
232 symbol
= accessing_symbol
[state1
];
233 fprintf (foutput
, _(" %-4s\tgo to state %d\n"), tags
[symbol
],
237 putc ('\n', foutput
);
241 #define END_TEST(end) \
243 if (column + strlen(buffer) > (end)) { \
244 fprintf (foutput, "%s\n ", buffer); \
258 /* rule # : LHS -> RHS */
259 fputs (_("\nGrammar\n"), foutput
);
260 for (i
= 1; i
<= nrules
; i
++)
261 /* Don't print rules disabled in reduce_grammar_tables. */
264 fprintf (foutput
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
265 rule
= &ritem
[rrhs
[i
]];
268 fprintf (foutput
, " %s", tags
[*rule
++]);
270 fputs (_(" /* empty */"), foutput
);
271 putc ('\n', foutput
);
274 /* TERMINAL (type #) : rule #s terminal is on RHS */
275 fputs (_("\nTerminals, with rules where they appear\n\n"), foutput
);
276 fprintf (foutput
, "%s (-1)\n", tags
[0]);
279 for (i
= 0; i
<= max_user_token_number
; i
++)
280 if (token_translations
[i
] != 2)
283 column
= strlen (tags
[token_translations
[i
]]);
284 fprintf (foutput
, "%s", tags
[token_translations
[i
]]);
286 sprintf (buffer
, " (%d)", i
);
288 for (j
= 1; j
<= nrules
; j
++)
290 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
291 if (*rule
== token_translations
[i
])
294 sprintf (buffer
+ strlen (buffer
), " %d", j
);
298 fprintf (foutput
, "%s\n", buffer
);
302 for (i
= 1; i
< ntokens
; i
++)
305 column
= strlen (tags
[i
]);
306 fprintf (foutput
, "%s", tags
[i
]);
308 sprintf (buffer
, " (%d)", i
);
310 for (j
= 1; j
<= nrules
; j
++)
312 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
316 sprintf (buffer
+ strlen (buffer
), " %d", j
);
320 fprintf (foutput
, "%s\n", buffer
);
323 fputs (_("\nNonterminals, with rules where they appear\n\n"), foutput
);
324 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
326 int left_count
= 0, right_count
= 0;
328 for (j
= 1; j
<= nrules
; j
++)
332 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
341 fprintf (foutput
, "%s", tags
[i
]);
342 column
= strlen (tags
[i
]);
343 sprintf (buffer
, " (%d)", i
);
349 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
351 for (j
= 1; j
<= nrules
; j
++)
355 sprintf (buffer
+ strlen (buffer
), " %d", j
);
362 sprintf (buffer
+ strlen (buffer
), ",");
364 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
365 for (j
= 1; j
<= nrules
; j
++)
367 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
371 sprintf (buffer
+ strlen (buffer
), " %d", j
);
376 fprintf (foutput
, "%s\n", buffer
);