]>
git.saurik.com Git - bison.git/blob - src/print.c
373c5ffc1d0d66a3614b27ceb5cc9e61911c9e98
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 short *accessing_symbol
;
32 extern core
**state_table
;
33 extern shifts
**shift_table
;
34 extern errs
**err_table
;
35 extern reductions
**reduction_table
;
36 extern char *consistent
;
37 extern char any_conflicts
;
38 extern char *conflicts
;
39 extern int final_state
;
41 extern void conflict_log
PARAMS ((void));
42 extern void verbose_conflict_log
PARAMS ((void));
43 extern void print_reductions
PARAMS ((int));
45 extern void terse
PARAMS ((void));
46 extern void verbose
PARAMS ((void));
48 #if 0 /* XXX currently unused. */
49 static void print_token
PARAMS ((int, int));
52 static void print_state
PARAMS ((int));
53 static void print_core
PARAMS ((int));
54 static void print_actions
PARAMS ((int));
55 static void print_grammar
PARAMS ((void));
71 verbose_conflict_log ();
75 for (i
= 0; i
< nstates
; i
++)
80 #if 0 /* XXX currently unused. */
82 print_token (int extnum
, int token
)
84 fprintf (foutput
, _(" type %d is %s\n"), extnum
, tags
[token
]);
90 print_state (int state
)
92 fprintf (foutput
, _("\n\nstate %d\n\n"), state
);
94 print_actions (state
);
99 print_core (int state
)
108 statep
= state_table
[state
];
114 for (i
= 0; i
< k
; i
++)
116 sp1
= sp
= ritem
+ statep
->items
[i
];
122 fprintf (foutput
, " %s -> ", tags
[rlhs
[rule
]]);
124 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
126 fprintf (foutput
, "%s ", tags
[*sp
]);
133 fprintf (foutput
, " %s", tags
[*sp
]);
137 fprintf (foutput
, _(" (rule %d)"), rule
);
138 putc ('\n', foutput
);
141 putc ('\n', foutput
);
146 print_actions (int state
)
157 shiftp
= shift_table
[state
];
158 redp
= reduction_table
[state
];
159 errp
= err_table
[state
];
161 if (!shiftp
&& !redp
)
163 if (final_state
== state
)
164 fprintf (foutput
, _(" $default\taccept\n"));
166 fprintf (foutput
, _(" NO ACTIONS\n"));
174 for (i
= 0; i
< k
; i
++)
176 if (!shiftp
->shifts
[i
])
178 state1
= shiftp
->shifts
[i
];
179 symbol
= accessing_symbol
[state1
];
180 /* The following line used to be turned off. */
183 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
184 fprintf (foutput
, _(" $ \tgo to state %d\n"), state1
);
186 fprintf (foutput
, _(" %-4s\tshift, and go to state %d\n"),
187 tags
[symbol
], state1
);
191 putc ('\n', foutput
);
205 for (j
= 0; j
< nerrs
; j
++)
209 symbol
= errp
->errs
[j
];
210 fprintf (foutput
, _(" %-4s\terror (nonassociative)\n"),
215 putc ('\n', foutput
);
218 if (consistent
[state
] && redp
)
220 rule
= redp
->rules
[0];
222 fprintf (foutput
, _(" $default\treduce using rule %d (%s)\n\n"),
227 print_reductions (state
);
234 if (!shiftp
->shifts
[i
])
236 state1
= shiftp
->shifts
[i
];
237 symbol
= accessing_symbol
[state1
];
238 fprintf (foutput
, _(" %-4s\tgo to state %d\n"), tags
[symbol
],
242 putc ('\n', foutput
);
246 #define END_TEST(end) \
248 if (column + strlen(buffer) > (end)) { \
249 fprintf (foutput, "%s\n ", buffer); \
263 /* rule # : LHS -> RHS */
264 fputs (_("\nGrammar\n"), foutput
);
265 for (i
= 1; i
<= nrules
; i
++)
266 /* Don't print rules disabled in reduce_grammar_tables. */
269 fprintf (foutput
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
270 rule
= &ritem
[rrhs
[i
]];
273 fprintf (foutput
, " %s", tags
[*rule
++]);
275 fputs (_(" /* empty */"), foutput
);
276 putc ('\n', foutput
);
279 /* TERMINAL (type #) : rule #s terminal is on RHS */
280 fputs (_("\nTerminals, with rules where they appear\n\n"), foutput
);
281 fprintf (foutput
, "%s (-1)\n", tags
[0]);
284 for (i
= 0; i
<= max_user_token_number
; i
++)
285 if (token_translations
[i
] != 2)
288 column
= strlen (tags
[token_translations
[i
]]);
289 fprintf (foutput
, "%s", tags
[token_translations
[i
]]);
291 sprintf (buffer
, " (%d)", i
);
293 for (j
= 1; j
<= nrules
; j
++)
295 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
296 if (*rule
== token_translations
[i
])
299 sprintf (buffer
+ strlen (buffer
), " %d", j
);
303 fprintf (foutput
, "%s\n", buffer
);
307 for (i
= 1; i
< ntokens
; i
++)
310 column
= strlen (tags
[i
]);
311 fprintf (foutput
, "%s", tags
[i
]);
313 sprintf (buffer
, " (%d)", i
);
315 for (j
= 1; j
<= nrules
; j
++)
317 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
321 sprintf (buffer
+ strlen (buffer
), " %d", j
);
325 fprintf (foutput
, "%s\n", buffer
);
328 fputs (_("\nNonterminals, with rules where they appear\n\n"), foutput
);
329 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
331 int left_count
= 0, right_count
= 0;
333 for (j
= 1; j
<= nrules
; j
++)
337 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
346 fprintf (foutput
, "%s", tags
[i
]);
347 column
= strlen (tags
[i
]);
348 sprintf (buffer
, " (%d)", i
);
354 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
356 for (j
= 1; j
<= nrules
; j
++)
360 sprintf (buffer
+ strlen (buffer
), " %d", j
);
367 sprintf (buffer
+ strlen (buffer
), ",");
369 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
370 for (j
= 1; j
<= nrules
; j
++)
372 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
376 sprintf (buffer
+ strlen (buffer
), " %d", j
);
381 fprintf (foutput
, "%s\n", buffer
);