]>
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
, int state
)
52 short *sitems
= state_table
[state
].state
->items
;
53 int snitems
= state_table
[state
].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
, int state
)
101 shifts
*shiftp
= state_table
[state
].shifts
;
102 reductions
*redp
= state_table
[state
].reductions
;
103 errs
*errp
= state_table
[state
].errs
;
105 if (!shiftp
->nshifts
&& !redp
)
107 if (final_state
== state
)
108 fprintf (out
, _(" $default\taccept\n"));
110 fprintf (out
, _(" NO ACTIONS\n"));
114 for (i
= 0; i
< shiftp
->nshifts
; i
++)
115 if (!SHIFT_IS_DISABLED (shiftp
, i
))
117 int state1
= shiftp
->shifts
[i
];
118 int symbol
= state_table
[state1
].accessing_symbol
;
119 /* The following line used to be turned off. */
122 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
124 _(" $ \tgo to state %d\n"), state1
);
127 _(" %-4s\tshift, and go to state %d\n"),
128 tags
[symbol
], state1
);
137 for (j
= 0; j
< errp
->nerrs
; j
++)
139 int symbol
= errp
->errs
[j
];
142 fprintf (out
, _(" %-4s\terror (nonassociative)\n"),
150 if (state_table
[state
].consistent
&& redp
)
152 int rule
= redp
->rules
[0];
153 int symbol
= rule_table
[rule
].lhs
;
154 fprintf (out
, _(" $default\treduce using rule %d (%s)\n\n"),
159 print_reductions (out
, state
);
162 if (i
< shiftp
->nshifts
)
164 for (; i
< shiftp
->nshifts
; i
++)
165 if (!SHIFT_IS_DISABLED (shiftp
, i
))
167 int state1
= shiftp
->shifts
[i
];
168 int symbol
= state_table
[state1
].accessing_symbol
;
169 fprintf (out
, _(" %-4s\tgo to state %d\n"),
170 tags
[symbol
], state1
);
178 print_state (FILE *out
, int state
)
180 fprintf (out
, _("state %d"), state
);
182 print_core (out
, state
);
183 print_actions (out
, state
);
187 /*-----------------------------------------.
188 | Print information on the whole grammar. |
189 `-----------------------------------------*/
191 #define END_TEST(End) \
193 if (column + strlen(buffer) > (End)) \
195 fprintf (out, "%s\n ", buffer); \
203 print_grammar (FILE *out
)
210 /* rule # : LHS -> RHS */
211 fprintf (out
, "%s\n\n", _("Grammar"));
212 fprintf (out
, " %s\n", _("Number, Line, Rule"));
213 for (i
= 1; i
<= nrules
; i
++)
214 /* Don't print rules disabled in reduce_grammar_tables. */
215 if (rule_table
[i
].useful
)
217 fprintf (out
, _(" %3d %3d %s ->"),
218 i
, rule_table
[i
].line
, tags
[rule_table
[i
].lhs
]);
219 rule
= &ritem
[rule_table
[i
].rhs
];
222 fprintf (out
, " %s", tags
[*rule
++]);
224 fprintf (out
, " /* %s */", _("empty"));
230 /* TERMINAL (type #) : rule #s terminal is on RHS */
231 fprintf (out
, "%s\n\n", _("Terminals, with rules where they appear"));
232 fprintf (out
, "%s (-1)\n", tags
[0]);
234 for (i
= 0; i
<= max_user_token_number
; i
++)
235 if (token_translations
[i
] != 2)
238 column
= strlen (tags
[token_translations
[i
]]);
239 fputs (tags
[token_translations
[i
]], out
);
241 sprintf (buffer
, " (%d)", i
);
243 for (j
= 1; j
<= nrules
; j
++)
244 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
245 if (*rule
== token_translations
[i
])
248 sprintf (buffer
+ strlen (buffer
), " %d", j
);
251 fprintf (out
, "%s\n", buffer
);
256 fprintf (out
, "%s\n\n", _("Nonterminals, with rules where they appear"));
257 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
259 int left_count
= 0, right_count
= 0;
261 for (j
= 1; j
<= nrules
; j
++)
263 if (rule_table
[j
].lhs
== i
)
265 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
274 fputs (tags
[i
], out
);
275 column
= strlen (tags
[i
]);
276 sprintf (buffer
, " (%d)", i
);
282 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
284 for (j
= 1; j
<= nrules
; j
++)
287 if (rule_table
[j
].lhs
== i
)
288 sprintf (buffer
+ strlen (buffer
), " %d", j
);
295 sprintf (buffer
+ strlen (buffer
), ",");
297 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
298 for (j
= 1; j
<= nrules
; j
++)
300 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
304 sprintf (buffer
+ strlen (buffer
), " %d", j
);
309 fprintf (out
, "%s\n", buffer
);
321 /* We used to use just .out if spec_name_prefix (-p) was used, but
322 that conflicts with Posix. */
323 FILE *out
= xfopen (spec_verbose_file
, "w");
325 size_t size
= obstack_object_size (&output_obstack
);
326 fwrite (obstack_finish (&output_obstack
), 1, size
, out
);
331 conflicts_output (out
);
335 /* New experimental feature: output all the items of a state,
336 not only its kernel. Requires to run closure, which need
337 memory allocation/deallocation. */
339 new_closure (nitems
);
340 for (i
= 0; i
< nstates
; i
++)
341 print_state (out
, i
);
347 obstack_free (&output_obstack
, NULL
);