]>
git.saurik.com Git - bison.git/blob - src/print.c
bd1e387c2b9bf16b0fc161153119ed0244869553
1 /* Print information on generated parser, for bison,
2 Copyright 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. */
27 #include "conflicts.h"
35 print_token (int extnum
, int token
)
37 fprintf (out
, _(" type %d is %s\n"), extnum
, tags
[token
]);
42 /*--------------------------------.
43 | Report information on a state. |
44 `--------------------------------*/
47 print_core (FILE *out
, int state
)
56 statep
= state_table
[state
];
62 for (i
= 0; i
< k
; i
++)
64 sp1
= sp
= ritem
+ statep
->items
[i
];
70 fprintf (out
, " %s -> ", tags
[rlhs
[rule
]]);
72 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
74 fprintf (out
, "%s ", tags
[*sp
]);
81 fprintf (out
, " %s", tags
[*sp
]);
85 fprintf (out
, _(" (rule %d)"), rule
);
93 print_actions (FILE *out
, int state
)
104 shiftp
= shift_table
[state
];
105 redp
= reduction_table
[state
];
106 errp
= err_table
[state
];
108 if (!shiftp
&& !redp
)
110 if (final_state
== state
)
111 fprintf (out
, _(" $default\taccept\n"));
113 fprintf (out
, _(" NO ACTIONS\n"));
121 for (i
= 0; i
< k
; i
++)
123 if (!shiftp
->shifts
[i
])
125 state1
= shiftp
->shifts
[i
];
126 symbol
= accessing_symbol
[state1
];
127 /* The following line used to be turned off. */
130 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
132 _(" $ \tgo to state %d\n"), state1
);
135 _(" %-4s\tshift, and go to state %d\n"),
136 tags
[symbol
], state1
);
154 for (j
= 0; j
< nerrs
; j
++)
158 symbol
= errp
->errs
[j
];
159 fprintf (out
, _(" %-4s\terror (nonassociative)\n"),
167 if (consistent
[state
] && redp
)
169 rule
= redp
->rules
[0];
171 fprintf (out
, _(" $default\treduce using rule %d (%s)\n\n"),
176 print_reductions (state
);
183 if (!shiftp
->shifts
[i
])
185 state1
= shiftp
->shifts
[i
];
186 symbol
= accessing_symbol
[state1
];
187 fprintf (out
, _(" %-4s\tgo to state %d\n"),
188 tags
[symbol
], state1
);
196 print_state (FILE *out
, int state
)
199 fprintf (out
, _("state %d"), state
);
201 print_core (out
, state
);
202 print_actions (out
, state
);
205 /*-----------------------------------------.
206 | Print information on the whole grammar. |
207 `-----------------------------------------*/
209 #define END_TEST(End) \
211 if (column + strlen(buffer) > (End)) \
213 fprintf (out, "%s\n ", buffer); \
221 print_grammar (FILE *out
)
228 /* rule # : LHS -> RHS */
229 fprintf (out
, "\n%s\n\n", _("Grammar"));
230 for (i
= 1; i
<= nrules
; i
++)
231 /* Don't print rules disabled in reduce_grammar_tables. */
234 fprintf (out
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
235 rule
= &ritem
[rrhs
[i
]];
238 fprintf (out
, " %s", tags
[*rule
++]);
240 fprintf (out
, " /* %s */", _("empty"));
244 /* TERMINAL (type #) : rule #s terminal is on RHS */
245 fprintf (out
, "\n%s\n\n", _("Terminals, with rules where they appear"));
246 fprintf (out
, "%s (-1)\n", tags
[0]);
248 for (i
= 0; i
<= max_user_token_number
; i
++)
249 if (token_translations
[i
] != 2)
252 column
= strlen (tags
[token_translations
[i
]]);
253 fputs (tags
[token_translations
[i
]], out
);
255 sprintf (buffer
, " (%d)", i
);
257 for (j
= 1; j
<= nrules
; j
++)
258 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
259 if (*rule
== token_translations
[i
])
262 sprintf (buffer
+ strlen (buffer
), " %d", j
);
265 fprintf (out
, "%s\n", buffer
);
268 fprintf (out
, "\n%s\n\n",
269 _("Nonterminals, with rules where they appear"));
270 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
272 int left_count
= 0, right_count
= 0;
274 for (j
= 1; j
<= nrules
; j
++)
278 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
287 fputs (tags
[i
], out
);
288 column
= strlen (tags
[i
]);
289 sprintf (buffer
, " (%d)", i
);
295 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
297 for (j
= 1; j
<= nrules
; j
++)
301 sprintf (buffer
+ strlen (buffer
), " %d", j
);
308 sprintf (buffer
+ strlen (buffer
), ",");
310 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
311 for (j
= 1; j
<= nrules
; j
++)
313 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
317 sprintf (buffer
+ strlen (buffer
), " %d", j
);
322 fprintf (out
, "%s\n", buffer
);
333 /* We used to use just .out if spec_name_prefix (-p) was used, but
334 that conflicts with Posix. */
335 FILE *out
= xfopen (spec_verbose_file
, "w");
337 size_t size
= obstack_object_size (&output_obstack
);
338 fwrite (obstack_finish (&output_obstack
), 1, size
, out
);
340 conflicts_output (out
);
344 for (i
= 0; i
< nstates
; i
++)
345 print_state (out
, i
);
349 obstack_free (&output_obstack
, NULL
);