]>
git.saurik.com Git - bison.git/blob - src/print.c
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. */
28 #include "conflicts.h"
36 print_token (int extnum
, int token
)
38 fprintf (foutput
, _(" type %d is %s\n"), extnum
, tags
[token
]);
43 /*================================\
44 | Report information on a state. |
45 \================================*/
48 print_core (int state
)
57 statep
= state_table
[state
];
63 for (i
= 0; i
< k
; i
++)
65 sp1
= sp
= ritem
+ statep
->items
[i
];
71 fprintf (foutput
, " %s -> ", tags
[rlhs
[rule
]]);
73 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
75 fprintf (foutput
, "%s ", tags
[*sp
]);
82 fprintf (foutput
, " %s", tags
[*sp
]);
86 fprintf (foutput
, _(" (rule %d)"), rule
);
94 print_actions (int state
)
105 shiftp
= shift_table
[state
];
106 redp
= reduction_table
[state
];
107 errp
= err_table
[state
];
109 if (!shiftp
&& !redp
)
111 if (final_state
== state
)
112 fprintf (foutput
, _(" $default\taccept\n"));
114 fprintf (foutput
, _(" NO ACTIONS\n"));
122 for (i
= 0; i
< k
; i
++)
124 if (!shiftp
->shifts
[i
])
126 state1
= shiftp
->shifts
[i
];
127 symbol
= accessing_symbol
[state1
];
128 /* The following line used to be turned off. */
131 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
132 fprintf (foutput
, _(" $ \tgo to state %d\n"), state1
);
134 fprintf (foutput
, _(" %-4s\tshift, and go to state %d\n"),
135 tags
[symbol
], state1
);
139 putc ('\n', foutput
);
153 for (j
= 0; j
< nerrs
; j
++)
157 symbol
= errp
->errs
[j
];
158 fprintf (foutput
, _(" %-4s\terror (nonassociative)\n"),
163 putc ('\n', foutput
);
166 if (consistent
[state
] && redp
)
168 rule
= redp
->rules
[0];
170 fprintf (foutput
, _(" $default\treduce using rule %d (%s)\n\n"),
175 print_reductions (state
);
182 if (!shiftp
->shifts
[i
])
184 state1
= shiftp
->shifts
[i
];
185 symbol
= accessing_symbol
[state1
];
186 fprintf (foutput
, _(" %-4s\tgo to state %d\n"), tags
[symbol
],
190 putc ('\n', foutput
);
195 print_state (int state
)
197 fputs ("\n\n", foutput
);
198 fprintf (foutput
, _("state %d"), state
);
199 fputs ("\n\n", foutput
);
201 print_actions (state
);
204 /*-----------------------------------------.
205 | Print information on the whole grammar. |
206 `-----------------------------------------*/
208 #define END_TEST(end) \
210 if (column + strlen(buffer) > (end)) { \
211 fprintf (foutput, "%s\n ", buffer); \
226 /* rule # : LHS -> RHS */
227 putc ('\n', foutput
);
228 fputs (_("Grammar"), foutput
);
229 putc ('\n', foutput
);
230 for (i
= 1; i
<= nrules
; i
++)
231 /* Don't print rules disabled in reduce_grammar_tables. */
234 fprintf (foutput
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
235 rule
= &ritem
[rrhs
[i
]];
238 fprintf (foutput
, " %s", tags
[*rule
++]);
240 fputs (_(" /* empty */"), foutput
);
241 putc ('\n', foutput
);
244 /* TERMINAL (type #) : rule #s terminal is on RHS */
245 fputs ("\n", foutput
);
246 fputs (_("Terminals, with rules where they appear"), foutput
);
247 fputs ("\n\n", foutput
);
248 fprintf (foutput
, "%s (-1)\n", tags
[0]);
251 for (i
= 0; i
<= max_user_token_number
; i
++)
252 if (token_translations
[i
] != 2)
255 column
= strlen (tags
[token_translations
[i
]]);
256 fprintf (foutput
, "%s", tags
[token_translations
[i
]]);
258 sprintf (buffer
, " (%d)", i
);
260 for (j
= 1; j
<= nrules
; j
++)
262 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
263 if (*rule
== token_translations
[i
])
266 sprintf (buffer
+ strlen (buffer
), " %d", j
);
270 fprintf (foutput
, "%s\n", buffer
);
274 for (i
= 1; i
< ntokens
; i
++)
277 column
= strlen (tags
[i
]);
278 fprintf (foutput
, "%s", tags
[i
]);
280 sprintf (buffer
, " (%d)", i
);
282 for (j
= 1; j
<= nrules
; j
++)
284 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
288 sprintf (buffer
+ strlen (buffer
), " %d", j
);
292 fprintf (foutput
, "%s\n", buffer
);
295 fputs ("\n", foutput
);
296 fputs (_("Nonterminals, with rules where they appear"), foutput
);
297 fputs ("\n\n", foutput
);
298 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
300 int left_count
= 0, right_count
= 0;
302 for (j
= 1; j
<= nrules
; j
++)
306 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
315 fprintf (foutput
, "%s", tags
[i
]);
316 column
= strlen (tags
[i
]);
317 sprintf (buffer
, " (%d)", i
);
323 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
325 for (j
= 1; j
<= nrules
; j
++)
329 sprintf (buffer
+ strlen (buffer
), " %d", j
);
336 sprintf (buffer
+ strlen (buffer
), ",");
338 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
339 for (j
= 1; j
<= nrules
; j
++)
341 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
345 sprintf (buffer
+ strlen (buffer
), " %d", j
);
350 fprintf (foutput
, "%s\n", buffer
);
366 for (i
= 0; i
< nstates
; i
++)