]>
git.saurik.com Git - bison.git/blob - src/print.c
96b64e8845ad783bca9fff1b757d9ab847d4a9dd
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
)
57 statep
= state_table
[state
].state
;
63 for (i
= 0; i
< k
; i
++)
65 sp1
= sp
= ritem
+ statep
->items
[i
];
71 fprintf (out
, " %s -> ", tags
[rule_table
[rule
].lhs
]);
73 for (sp
= ritem
+ rule_table
[rule
].rhs
; sp
< sp1
; sp
++)
75 fprintf (out
, "%s ", tags
[*sp
]);
82 fprintf (out
, " %s", tags
[*sp
]);
86 fprintf (out
, _(" (rule %d)"), rule
);
94 print_actions (FILE *out
, int state
)
105 shiftp
= state_table
[state
].shift_table
;
106 redp
= state_table
[state
].reduction_table
;
107 errp
= err_table
[state
];
109 if (!shiftp
&& !redp
)
111 if (final_state
== state
)
112 fprintf (out
, _(" $default\taccept\n"));
114 fprintf (out
, _(" NO ACTIONS\n"));
122 for (i
= 0; i
< k
; i
++)
124 if (!shiftp
->shifts
[i
])
126 state1
= shiftp
->shifts
[i
];
127 symbol
= state_table
[state1
].accessing_symbol
;
128 /* The following line used to be turned off. */
131 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
133 _(" $ \tgo to state %d\n"), state1
);
136 _(" %-4s\tshift, and go to state %d\n"),
137 tags
[symbol
], state1
);
155 for (j
= 0; j
< nerrs
; j
++)
159 symbol
= errp
->errs
[j
];
160 fprintf (out
, _(" %-4s\terror (nonassociative)\n"),
168 if (state_table
[state
].consistent
&& redp
)
170 rule
= redp
->rules
[0];
171 symbol
= rule_table
[rule
].lhs
;
172 fprintf (out
, _(" $default\treduce using rule %d (%s)\n\n"),
177 print_reductions (out
, state
);
184 if (!shiftp
->shifts
[i
])
186 state1
= shiftp
->shifts
[i
];
187 symbol
= state_table
[state1
].accessing_symbol
;
188 fprintf (out
, _(" %-4s\tgo to state %d\n"),
189 tags
[symbol
], state1
);
197 print_state (FILE *out
, int state
)
200 fprintf (out
, _("state %d"), state
);
202 print_core (out
, state
);
203 print_actions (out
, state
);
206 /*-----------------------------------------.
207 | Print information on the whole grammar. |
208 `-----------------------------------------*/
210 #define END_TEST(End) \
212 if (column + strlen(buffer) > (End)) \
214 fprintf (out, "%s\n ", buffer); \
222 print_grammar (FILE *out
)
229 /* rule # : LHS -> RHS */
230 fprintf (out
, "\n%s\n\n", _("Grammar"));
231 for (i
= 1; i
<= nrules
; i
++)
232 /* Don't print rules disabled in reduce_grammar_tables. */
233 if (rule_table
[i
].lhs
>= 0)
235 fprintf (out
, _("rule %-4d %s ->"), i
, tags
[rule_table
[i
].lhs
]);
236 rule
= &ritem
[rule_table
[i
].rhs
];
239 fprintf (out
, " %s", tags
[*rule
++]);
241 fprintf (out
, " /* %s */", _("empty"));
245 /* TERMINAL (type #) : rule #s terminal is on RHS */
246 fprintf (out
, "\n%s\n\n", _("Terminals, with rules where they appear"));
247 fprintf (out
, "%s (-1)\n", tags
[0]);
249 for (i
= 0; i
<= max_user_token_number
; i
++)
250 if (token_translations
[i
] != 2)
253 column
= strlen (tags
[token_translations
[i
]]);
254 fputs (tags
[token_translations
[i
]], out
);
256 sprintf (buffer
, " (%d)", i
);
258 for (j
= 1; j
<= nrules
; j
++)
259 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
260 if (*rule
== token_translations
[i
])
263 sprintf (buffer
+ strlen (buffer
), " %d", j
);
266 fprintf (out
, "%s\n", buffer
);
269 fprintf (out
, "\n%s\n\n",
270 _("Nonterminals, with rules where they appear"));
271 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
273 int left_count
= 0, right_count
= 0;
275 for (j
= 1; j
<= nrules
; j
++)
277 if (rule_table
[j
].lhs
== i
)
279 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
288 fputs (tags
[i
], out
);
289 column
= strlen (tags
[i
]);
290 sprintf (buffer
, " (%d)", i
);
296 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
298 for (j
= 1; j
<= nrules
; j
++)
301 if (rule_table
[j
].lhs
== i
)
302 sprintf (buffer
+ strlen (buffer
), " %d", j
);
309 sprintf (buffer
+ strlen (buffer
), ",");
311 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
312 for (j
= 1; j
<= nrules
; j
++)
314 for (rule
= &ritem
[rule_table
[j
].rhs
]; *rule
> 0; rule
++)
318 sprintf (buffer
+ strlen (buffer
), " %d", j
);
323 fprintf (out
, "%s\n", buffer
);
334 /* We used to use just .out if spec_name_prefix (-p) was used, but
335 that conflicts with Posix. */
336 FILE *out
= xfopen (spec_verbose_file
, "w");
338 size_t size
= obstack_object_size (&output_obstack
);
339 fwrite (obstack_finish (&output_obstack
), 1, size
, out
);
342 conflicts_output (out
);
346 for (i
= 0; i
< nstates
; i
++)
347 print_state (out
, i
);
351 obstack_free (&output_obstack
, NULL
);