]>
git.saurik.com Git - bison.git/blob - src/print.c
bf3fce87f05a661dadee565eee472a5d7c447904
1 /* Print information on generated parser, for bison,
2 Copyright (C) 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"
33 extern int final_state
;
37 print_token (int extnum
, int token
)
39 fprintf (foutput
, _(" type %d is %s\n"), extnum
, tags
[token
]);
44 /*================================\
45 | Report information on a state. |
46 \================================*/
49 print_core (int state
)
58 statep
= state_table
[state
];
64 for (i
= 0; i
< k
; i
++)
66 sp1
= sp
= ritem
+ statep
->items
[i
];
72 fprintf (foutput
, " %s -> ", tags
[rlhs
[rule
]]);
74 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
76 fprintf (foutput
, "%s ", tags
[*sp
]);
83 fprintf (foutput
, " %s", tags
[*sp
]);
87 fprintf (foutput
, _(" (rule %d)"), rule
);
95 print_actions (int state
)
106 shiftp
= shift_table
[state
];
107 redp
= reduction_table
[state
];
108 errp
= err_table
[state
];
110 if (!shiftp
&& !redp
)
112 if (final_state
== state
)
113 fprintf (foutput
, _(" $default\taccept\n"));
115 fprintf (foutput
, _(" NO ACTIONS\n"));
123 for (i
= 0; i
< k
; i
++)
125 if (!shiftp
->shifts
[i
])
127 state1
= shiftp
->shifts
[i
];
128 symbol
= accessing_symbol
[state1
];
129 /* The following line used to be turned off. */
132 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
133 fprintf (foutput
, _(" $ \tgo to state %d\n"), state1
);
135 fprintf (foutput
, _(" %-4s\tshift, and go to state %d\n"),
136 tags
[symbol
], state1
);
140 putc ('\n', foutput
);
154 for (j
= 0; j
< nerrs
; j
++)
158 symbol
= errp
->errs
[j
];
159 fprintf (foutput
, _(" %-4s\terror (nonassociative)\n"),
164 putc ('\n', foutput
);
167 if (consistent
[state
] && redp
)
169 rule
= redp
->rules
[0];
171 fprintf (foutput
, _(" $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 (foutput
, _(" %-4s\tgo to state %d\n"), tags
[symbol
],
191 putc ('\n', foutput
);
196 print_state (int state
)
198 fprintf (foutput
, _("\n\nstate %d\n\n"), state
);
200 print_actions (state
);
203 /*-----------------------------------------.
204 | Print information on the whole grammar. |
205 `-----------------------------------------*/
207 #define END_TEST(end) \
209 if (column + strlen(buffer) > (end)) { \
210 fprintf (foutput, "%s\n ", buffer); \
225 /* rule # : LHS -> RHS */
226 fputs (_("\nGrammar\n"), foutput
);
227 for (i
= 1; i
<= nrules
; i
++)
228 /* Don't print rules disabled in reduce_grammar_tables. */
231 fprintf (foutput
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
232 rule
= &ritem
[rrhs
[i
]];
235 fprintf (foutput
, " %s", tags
[*rule
++]);
237 fputs (_(" /* empty */"), foutput
);
238 putc ('\n', foutput
);
241 /* TERMINAL (type #) : rule #s terminal is on RHS */
242 fputs (_("\nTerminals, with rules where they appear\n\n"), foutput
);
243 fprintf (foutput
, "%s (-1)\n", tags
[0]);
246 for (i
= 0; i
<= max_user_token_number
; i
++)
247 if (token_translations
[i
] != 2)
250 column
= strlen (tags
[token_translations
[i
]]);
251 fprintf (foutput
, "%s", tags
[token_translations
[i
]]);
253 sprintf (buffer
, " (%d)", i
);
255 for (j
= 1; j
<= nrules
; j
++)
257 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
258 if (*rule
== token_translations
[i
])
261 sprintf (buffer
+ strlen (buffer
), " %d", j
);
265 fprintf (foutput
, "%s\n", buffer
);
269 for (i
= 1; i
< ntokens
; i
++)
272 column
= strlen (tags
[i
]);
273 fprintf (foutput
, "%s", tags
[i
]);
275 sprintf (buffer
, " (%d)", i
);
277 for (j
= 1; j
<= nrules
; j
++)
279 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
283 sprintf (buffer
+ strlen (buffer
), " %d", j
);
287 fprintf (foutput
, "%s\n", buffer
);
290 fputs (_("\nNonterminals, with rules where they appear\n\n"), foutput
);
291 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
293 int left_count
= 0, right_count
= 0;
295 for (j
= 1; j
<= nrules
; j
++)
299 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
308 fprintf (foutput
, "%s", tags
[i
]);
309 column
= strlen (tags
[i
]);
310 sprintf (buffer
, " (%d)", i
);
316 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
318 for (j
= 1; j
<= nrules
; j
++)
322 sprintf (buffer
+ strlen (buffer
), " %d", j
);
329 sprintf (buffer
+ strlen (buffer
), ",");
331 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
332 for (j
= 1; j
<= nrules
; j
++)
334 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
338 sprintf (buffer
+ strlen (buffer
), " %d", j
);
343 fprintf (foutput
, "%s\n", buffer
);
359 for (i
= 0; i
< nstates
; i
++)