]>
git.saurik.com Git - bison.git/blob - src/print.c
9ac1feb3b34c5e8bf365a46262696d3a9bd33357
1 /* Print information on generated parser, for bison,
2 Copyright 1984, 1986, 1989, 2000, 2001 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. */
27 #include "conflicts.h"
36 print_token (int extnum
, int token
)
38 fprintf (out
, _(" type %d is %s\n"), extnum
, tags
[token
]);
43 /*--------------------------------.
44 | Report information on a state. |
45 `--------------------------------*/
48 print_core (FILE *out
, int state
)
51 core
*statep
= state_table
[state
].state
;
56 for (i
= 0; i
< statep
->nitems
; i
++)
62 sp1
= sp
= ritem
+ statep
->items
[i
];
68 fprintf (out
, " %s -> ", tags
[rule_table
[rule
].lhs
]);
70 for (sp
= ritem
+ rule_table
[rule
].rhs
; sp
< sp1
; sp
++)
71 fprintf (out
, "%s ", tags
[*sp
]);
75 for (/* Nothing */; *sp
> 0; ++sp
)
76 fprintf (out
, " %s", tags
[*sp
]);
78 fprintf (out
, _(" (rule %d)"), rule
);
86 print_actions (FILE *out
, int state
)
91 shifts
*shiftp
= state_table
[state
].shift_table
;
92 reductions
*redp
= state_table
[state
].reduction_table
;
93 errs
*errp
= err_table
[state
];
97 if (final_state
== state
)
98 fprintf (out
, _(" $default\taccept\n"));
100 fprintf (out
, _(" NO ACTIONS\n"));
108 for (i
= 0; i
< k
; i
++)
111 int state1
= shiftp
->shifts
[i
];
114 symbol
= state_table
[state1
].accessing_symbol
;
115 /* The following line used to be turned off. */
118 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
120 _(" $ \tgo to state %d\n"), state1
);
123 _(" %-4s\tshift, and go to state %d\n"),
124 tags
[symbol
], state1
);
139 for (j
= 0; j
< errp
->nerrs
; j
++)
141 int symbol
= errp
->errs
[j
];
144 fprintf (out
, _(" %-4s\terror (nonassociative)\n"),
152 if (state_table
[state
].consistent
&& redp
)
154 int rule
= redp
->rules
[0];
155 int symbol
= rule_table
[rule
].lhs
;
156 fprintf (out
, _(" $default\treduce using rule %d (%s)\n\n"),
161 print_reductions (out
, state
);
169 int state1
= shiftp
->shifts
[i
];
172 symbol
= state_table
[state1
].accessing_symbol
;
173 fprintf (out
, _(" %-4s\tgo to state %d\n"),
174 tags
[symbol
], state1
);
182 print_state (FILE *out
, int state
)
184 fprintf (out
, _("state %d"), state
);
186 print_core (out
, state
);
187 print_actions (out
, state
);
191 /*-----------------------------------------.
192 | Print information on the whole grammar. |
193 `-----------------------------------------*/
195 #define END_TEST(End) \
197 if (column + strlen(buffer) > (End)) \
199 fprintf (out, "%s\n ", buffer); \
207 print_grammar (FILE *out
)
214 /* rule # : LHS -> RHS */
215 fprintf (out
, "%s\n\n", _("Grammar"));
216 fprintf (out
, " %s\n", _("Number, Line, Rule"));
217 for (i
= 1; i
<= nrules
; i
++)
218 /* Don't print rules disabled in reduce_grammar_tables. */
219 if (rule_table
[i
].useful
)
221 fprintf (out
, _(" %3d %3d %s ->"),
222 i
, rule_table
[i
].line
, tags
[rule_table
[i
].lhs
]);
223 rule
= &ritem
[rule_table
[i
].rhs
];
226 fprintf (out
, " %s", tags
[*rule
++]);
228 fprintf (out
, " /* %s */", _("empty"));
234 /* TERMINAL (type #) : rule #s terminal is on RHS */
235 fprintf (out
, "%s\n\n", _("Terminals, with rules where they appear"));
236 fprintf (out
, "%s (-1)\n", tags
[0]);
238 for (i
= 0; i
<= max_user_token_number
; i
++)
239 if (token_translations
[i
] != 2)
242 column
= strlen (tags
[token_translations
[i
]]);
243 fputs (tags
[token_translations
[i
]], out
);
245 sprintf (buffer
, " (%d)", i
);
247 for (j
= 1; j
<= nrules
; j
++)
248 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
249 if (*rule
== token_translations
[i
])
252 sprintf (buffer
+ strlen (buffer
), " %d", j
);
255 fprintf (out
, "%s\n", buffer
);
260 fprintf (out
, "%s\n\n", _("Nonterminals, with rules where they appear"));
261 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
263 int left_count
= 0, right_count
= 0;
265 for (j
= 1; j
<= nrules
; j
++)
267 if (rule_table
[j
].lhs
== i
)
269 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
278 fputs (tags
[i
], out
);
279 column
= strlen (tags
[i
]);
280 sprintf (buffer
, " (%d)", i
);
286 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
288 for (j
= 1; j
<= nrules
; j
++)
291 if (rule_table
[j
].lhs
== i
)
292 sprintf (buffer
+ strlen (buffer
), " %d", j
);
299 sprintf (buffer
+ strlen (buffer
), ",");
301 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
302 for (j
= 1; j
<= nrules
; j
++)
304 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
308 sprintf (buffer
+ strlen (buffer
), " %d", j
);
313 fprintf (out
, "%s\n", buffer
);
325 /* We used to use just .out if spec_name_prefix (-p) was used, but
326 that conflicts with Posix. */
327 FILE *out
= xfopen (spec_verbose_file
, "w");
329 size_t size
= obstack_object_size (&output_obstack
);
330 fwrite (obstack_finish (&output_obstack
), 1, size
, out
);
335 conflicts_output (out
);
339 for (i
= 0; i
< nstates
; i
++)
340 print_state (out
, i
);
344 obstack_free (&output_obstack
, NULL
);