]>
git.saurik.com Git - bison.git/blob - src/print.c
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. */
28 #include "conflicts.h"
36 print_token (int extnum
, int token
)
38 obstack_fgrow2 (&output_obstack
, _(" type %d is %s\n"), extnum
, tags
[token
]);
43 /*================================\
44 | Report information on a state. |
45 \================================*/
48 print_core (int state
)
57 statep
= state_table
[state
];
63 for (i
= 0; i
< k
; i
++)
65 sp1
= sp
= ritem
+ statep
->items
[i
];
71 obstack_fgrow1 (&output_obstack
, " %s -> ", tags
[rlhs
[rule
]]);
73 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
75 obstack_fgrow1 (&output_obstack
, "%s ", tags
[*sp
]);
78 obstack_1grow (&output_obstack
, '.');
82 obstack_fgrow1 (&output_obstack
, " %s", tags
[*sp
]);
86 obstack_fgrow1 (&output_obstack
, _(" (rule %d)"), rule
);
87 obstack_1grow (&output_obstack
, '\n');
90 obstack_1grow (&output_obstack
, '\n');
94 print_actions (int state
)
105 shiftp
= shift_table
[state
];
106 redp
= reduction_table
[state
];
107 errp
= err_table
[state
];
109 if (!shiftp
&& !redp
)
111 if (final_state
== state
)
112 obstack_sgrow (&output_obstack
, _(" $default\taccept\n"));
114 obstack_sgrow (&output_obstack
, _(" NO ACTIONS\n"));
122 for (i
= 0; i
< k
; i
++)
124 if (!shiftp
->shifts
[i
])
126 state1
= shiftp
->shifts
[i
];
127 symbol
= accessing_symbol
[state1
];
128 /* The following line used to be turned off. */
131 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
132 obstack_fgrow1 (&output_obstack
,
133 _(" $ \tgo to state %d\n"), state1
);
135 obstack_fgrow2 (&output_obstack
,
136 _(" %-4s\tshift, and go to state %d\n"),
137 tags
[symbol
], state1
);
141 obstack_1grow (&output_obstack
, '\n');
155 for (j
= 0; j
< nerrs
; j
++)
159 symbol
= errp
->errs
[j
];
160 obstack_fgrow1 (&output_obstack
, _(" %-4s\terror (nonassociative)\n"),
165 obstack_1grow (&output_obstack
, '\n');
168 if (consistent
[state
] && redp
)
170 rule
= redp
->rules
[0];
172 obstack_fgrow2 (&output_obstack
,
173 _(" $default\treduce using rule %d (%s)\n\n"),
178 print_reductions (state
);
185 if (!shiftp
->shifts
[i
])
187 state1
= shiftp
->shifts
[i
];
188 symbol
= accessing_symbol
[state1
];
189 obstack_fgrow2 (&output_obstack
,
190 _(" %-4s\tgo to state %d\n"),
191 tags
[symbol
], state1
);
194 obstack_1grow (&output_obstack
, '\n');
199 print_state (int state
)
201 obstack_sgrow (&output_obstack
, "\n\n");
202 obstack_fgrow1 (&output_obstack
, _("state %d"), state
);
203 obstack_sgrow (&output_obstack
, "\n\n");
205 print_actions (state
);
208 /*-----------------------------------------.
209 | Print information on the whole grammar. |
210 `-----------------------------------------*/
212 #define END_TEST(End) \
214 if (column + strlen(buffer) > (End)) \
216 obstack_fgrow1 (&output_obstack, "%s\n ", buffer); \
231 /* rule # : LHS -> RHS */
232 obstack_1grow (&output_obstack
, '\n');
233 obstack_sgrow (&output_obstack
, _("Grammar"));
234 obstack_1grow (&output_obstack
, '\n');
235 for (i
= 1; i
<= nrules
; i
++)
236 /* Don't print rules disabled in reduce_grammar_tables. */
239 obstack_fgrow2 (&output_obstack
,
240 _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
241 rule
= &ritem
[rrhs
[i
]];
244 obstack_fgrow1 (&output_obstack
, " %s", tags
[*rule
++]);
246 obstack_sgrow (&output_obstack
, _(" /* empty */"));
247 obstack_1grow (&output_obstack
, '\n');
250 /* TERMINAL (type #) : rule #s terminal is on RHS */
251 obstack_sgrow (&output_obstack
, "\n");
252 obstack_sgrow (&output_obstack
,
253 _("Terminals, with rules where they appear"));
254 obstack_sgrow (&output_obstack
, "\n\n");
255 obstack_fgrow1 (&output_obstack
, "%s (-1)\n", tags
[0]);
258 for (i
= 0; i
<= max_user_token_number
; i
++)
259 if (token_translations
[i
] != 2)
262 column
= strlen (tags
[token_translations
[i
]]);
263 obstack_sgrow (&output_obstack
, tags
[token_translations
[i
]]);
265 sprintf (buffer
, " (%d)", i
);
267 for (j
= 1; j
<= nrules
; j
++)
268 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
269 if (*rule
== token_translations
[i
])
272 sprintf (buffer
+ strlen (buffer
), " %d", j
);
275 obstack_fgrow1 (&output_obstack
, "%s\n", buffer
);
280 for (i
= 1; i
< ntokens
; i
++)
283 column
= strlen (tags
[i
]);
284 obstack_sgrow (&output_obstack
, tags
[i
]);
286 sprintf (buffer
, " (%d)", i
);
288 for (j
= 1; j
<= nrules
; j
++)
289 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
293 sprintf (buffer
+ strlen (buffer
), " %d", j
);
296 obstack_fgrow1 (&output_obstack
, "%s\n", buffer
);
300 obstack_sgrow (&output_obstack
, "\n");
301 obstack_sgrow (&output_obstack
,
302 _("Nonterminals, with rules where they appear"));
303 obstack_sgrow (&output_obstack
, "\n\n");
304 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
306 int left_count
= 0, right_count
= 0;
308 for (j
= 1; j
<= nrules
; j
++)
312 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
321 obstack_sgrow (&output_obstack
, tags
[i
]);
322 column
= strlen (tags
[i
]);
323 sprintf (buffer
, " (%d)", i
);
329 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
331 for (j
= 1; j
<= nrules
; j
++)
335 sprintf (buffer
+ strlen (buffer
), " %d", j
);
342 sprintf (buffer
+ strlen (buffer
), ",");
344 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
345 for (j
= 1; j
<= nrules
; j
++)
347 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
351 sprintf (buffer
+ strlen (buffer
), " %d", j
);
356 obstack_fgrow1 (&output_obstack
, "%s\n", buffer
);
372 for (i
= 0; i
< nstates
; i
++)