]>
git.saurik.com Git - bison.git/blob - src/print.c
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"
37 print_token (int extnum
, int token
)
39 fprintf (out
, _(" type %d is %s\n"), extnum
, tags
[token
]);
44 /*--------------------------------.
45 | Report information on a state. |
46 `--------------------------------*/
49 print_core (FILE *out
, state_t
*state
)
52 short *sitems
= state
->items
;
53 int snitems
= state
->nitems
;
55 /* New experimental feature: if TRACE_FLAGS output all the items of
56 a state, not only its kernel. */
59 closure (sitems
, snitems
);
66 for (i
= 0; i
< snitems
; i
++)
72 sp1
= sp
= ritem
+ sitems
[i
];
78 fprintf (out
, " %s -> ", tags
[rule_table
[rule
].lhs
]);
80 for (sp
= ritem
+ rule_table
[rule
].rhs
; sp
< sp1
; sp
++)
81 fprintf (out
, "%s ", tags
[*sp
]);
85 for (/* Nothing */; *sp
> 0; ++sp
)
86 fprintf (out
, " %s", tags
[*sp
]);
88 fprintf (out
, _(" (rule %d)"), rule
);
97 print_actions (FILE *out
, state_t
*state
)
101 shifts
*shiftp
= state
->shifts
;
102 reductions
*redp
= state
->reductions
;
103 errs
*errp
= state
->errs
;
105 if (!shiftp
->nshifts
&& !redp
)
107 if (final_state
== state
->number
)
108 fprintf (out
, _(" $default\taccept\n"));
110 fprintf (out
, _(" NO ACTIONS\n"));
114 for (i
= 0; i
< shiftp
->nshifts
&& SHIFT_IS_SHIFT (shiftp
, i
); i
++)
115 if (!SHIFT_IS_DISABLED (shiftp
, i
))
117 int state1
= shiftp
->shifts
[i
];
118 int symbol
= state_table
[state1
]->accessing_symbol
;
120 _(" %-4s\tshift, and go to state %d\n"),
121 tags
[symbol
], state1
);
130 for (j
= 0; j
< errp
->nerrs
; j
++)
132 int symbol
= errp
->errs
[j
];
135 fprintf (out
, _(" %-4s\terror (nonassociative)\n"),
143 if (state
->consistent
&& redp
)
145 int rule
= redp
->rules
[0];
146 int symbol
= rule_table
[rule
].lhs
;
147 fprintf (out
, _(" $default\treduce using rule %d (%s)\n\n"),
152 print_reductions (out
, state
);
155 if (i
< shiftp
->nshifts
)
157 for (; i
< shiftp
->nshifts
; i
++)
158 if (!SHIFT_IS_DISABLED (shiftp
, i
))
160 int state1
= shiftp
->shifts
[i
];
161 int symbol
= state_table
[state1
]->accessing_symbol
;
162 fprintf (out
, _(" %-4s\tgo to state %d\n"),
163 tags
[symbol
], state1
);
171 print_state (FILE *out
, state_t
*state
)
173 fprintf (out
, _("state %d"), state
->number
);
175 print_core (out
, state
);
176 print_actions (out
, state
);
180 /*-----------------------------------------.
181 | Print information on the whole grammar. |
182 `-----------------------------------------*/
184 #define END_TEST(End) \
186 if (column + strlen(buffer) > (End)) \
188 fprintf (out, "%s\n ", buffer); \
196 print_grammar (FILE *out
)
203 /* rule # : LHS -> RHS */
204 fprintf (out
, "%s\n\n", _("Grammar"));
205 fprintf (out
, " %s\n", _("Number, Line, Rule"));
206 for (i
= 1; i
<= nrules
; i
++)
207 /* Don't print rules disabled in reduce_grammar_tables. */
208 if (rule_table
[i
].useful
)
210 fprintf (out
, _(" %3d %3d %s ->"),
211 i
, rule_table
[i
].line
, tags
[rule_table
[i
].lhs
]);
212 rule
= &ritem
[rule_table
[i
].rhs
];
215 fprintf (out
, " %s", tags
[*rule
++]);
217 fprintf (out
, " /* %s */", _("empty"));
223 /* TERMINAL (type #) : rule #s terminal is on RHS */
224 fprintf (out
, "%s\n\n", _("Terminals, with rules where they appear"));
225 fprintf (out
, "%s (-1)\n", tags
[0]);
227 for (i
= 0; i
<= max_user_token_number
; i
++)
228 if (token_translations
[i
] != 2)
231 column
= strlen (tags
[token_translations
[i
]]);
232 fputs (tags
[token_translations
[i
]], out
);
234 sprintf (buffer
, " (%d)", i
);
236 for (j
= 1; j
<= nrules
; j
++)
237 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
238 if (*rule
== token_translations
[i
])
241 sprintf (buffer
+ strlen (buffer
), " %d", j
);
244 fprintf (out
, "%s\n", buffer
);
249 fprintf (out
, "%s\n\n", _("Nonterminals, with rules where they appear"));
250 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
252 int left_count
= 0, right_count
= 0;
254 for (j
= 1; j
<= nrules
; j
++)
256 if (rule_table
[j
].lhs
== i
)
258 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
267 fputs (tags
[i
], out
);
268 column
= strlen (tags
[i
]);
269 sprintf (buffer
, " (%d)", i
);
275 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
277 for (j
= 1; j
<= nrules
; j
++)
280 if (rule_table
[j
].lhs
== i
)
281 sprintf (buffer
+ strlen (buffer
), " %d", j
);
288 sprintf (buffer
+ strlen (buffer
), ",");
290 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
291 for (j
= 1; j
<= nrules
; j
++)
293 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
297 sprintf (buffer
+ strlen (buffer
), " %d", j
);
302 fprintf (out
, "%s\n", buffer
);
312 /* We used to use just .out if SPEC_NAME_PREFIX (-p) was used, but
313 that conflicts with Posix. */
314 FILE *out
= xfopen (spec_verbose_file
, "w");
316 size_t size
= obstack_object_size (&output_obstack
);
317 fwrite (obstack_finish (&output_obstack
), 1, size
, out
);
318 obstack_free (&output_obstack
, NULL
);
324 conflicts_output (out
);
328 /* New experimental feature: output all the items of a state,
329 not only its kernel. Requires to run closure, which need
330 memory allocation/deallocation. */
332 new_closure (nitems
);
333 for (i
= 0; i
< nstates
; i
++)
334 print_state (out
, state_table
[i
]);