]>
git.saurik.com Git - bison.git/blob - src/print.c
1 /* Print information on generated parser, for bison,
2 Copyright (C) 1984, 1986, 1989 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. */
31 extern short *accessing_symbol
;
32 extern core
**state_table
;
33 extern shifts
**shift_table
;
34 extern errs
**err_table
;
35 extern reductions
**reduction_table
;
36 extern char *consistent
;
37 extern char any_conflicts
;
38 extern char *conflicts
;
39 extern int final_state
;
41 extern void conflict_log
PARAMS((void));
42 extern void verbose_conflict_log
PARAMS((void));
43 extern void print_reductions
PARAMS((int));
45 extern void terse
PARAMS((void));
46 extern void verbose
PARAMS((void));
48 #if 0 /* XXX currently unused. */
49 static void print_token
PARAMS((int, int));
52 static void print_state
PARAMS((int));
53 static void print_core
PARAMS((int));
54 static void print_actions
PARAMS((int));
55 static void print_grammar
PARAMS((void));
73 verbose_conflict_log();
77 for (i
= 0; i
< nstates
; i
++)
84 #if 0 /* XXX currently unused. */
86 print_token (int extnum
, int token
)
88 fprintf(foutput
, _(" type %d is %s\n"), extnum
, tags
[token
]);
94 print_state (int state
)
96 fprintf(foutput
, _("\n\nstate %d\n\n"), state
);
103 print_core (int state
)
108 register core
*statep
;
112 statep
= state_table
[state
];
117 for (i
= 0; i
< k
; i
++)
119 sp1
= sp
= ritem
+ statep
->items
[i
];
125 fprintf(foutput
, " %s -> ", tags
[rlhs
[rule
]]);
127 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
129 fprintf(foutput
, "%s ", tags
[*sp
]);
136 fprintf(foutput
, " %s", tags
[*sp
]);
140 fprintf (foutput
, _(" (rule %d)"), rule
);
149 print_actions (int state
)
155 register shifts
*shiftp
;
157 register reductions
*redp
;
160 shiftp
= shift_table
[state
];
161 redp
= reduction_table
[state
];
162 errp
= err_table
[state
];
164 if (!shiftp
&& !redp
)
166 if (final_state
== state
)
167 fprintf(foutput
, _(" $default\taccept\n"));
169 fprintf(foutput
, _(" NO ACTIONS\n"));
177 for (i
= 0; i
< k
; i
++)
179 if (! shiftp
->shifts
[i
]) continue;
180 state1
= shiftp
->shifts
[i
];
181 symbol
= accessing_symbol
[state1
];
182 /* The following line used to be turned off. */
183 if (ISVAR(symbol
)) break;
184 if (symbol
==0) /* I.e. strcmp(tags[symbol],"$")==0 */
185 fprintf(foutput
, _(" $ \tgo to state %d\n"), state1
);
187 fprintf(foutput
, _(" %-4s\tshift, and go to state %d\n"),
188 tags
[symbol
], state1
);
206 for (j
= 0; j
< nerrs
; j
++)
208 if (! errp
->errs
[j
]) continue;
209 symbol
= errp
->errs
[j
];
210 fprintf(foutput
, _(" %-4s\terror (nonassociative)\n"), tags
[symbol
]);
217 if (consistent
[state
] && redp
)
219 rule
= redp
->rules
[0];
221 fprintf(foutput
, _(" $default\treduce using rule %d (%s)\n\n"),
226 print_reductions(state
);
233 if (! shiftp
->shifts
[i
]) continue;
234 state1
= shiftp
->shifts
[i
];
235 symbol
= accessing_symbol
[state1
];
236 fprintf(foutput
, _(" %-4s\tgo to state %d\n"), tags
[symbol
], state1
);
243 #define END_TEST(end) \
245 if (column + strlen(buffer) > (end)) { \
246 fprintf (foutput, "%s\n ", buffer); \
260 /* rule # : LHS -> RHS */
261 fputs(_("\nGrammar\n"), foutput
);
262 for (i
= 1; i
<= nrules
; i
++)
263 /* Don't print rules disabled in reduce_grammar_tables. */
266 fprintf(foutput
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
267 rule
= &ritem
[rrhs
[i
]];
270 fprintf(foutput
, " %s", tags
[*rule
++]);
272 fputs (_(" /* empty */"), foutput
);
276 /* TERMINAL (type #) : rule #s terminal is on RHS */
277 fputs(_("\nTerminals, with rules where they appear\n\n"), foutput
);
278 fprintf(foutput
, "%s (-1)\n", tags
[0]);
281 for (i
= 0; i
<= max_user_token_number
; i
++)
282 if (token_translations
[i
] != 2)
285 column
= strlen (tags
[token_translations
[i
]]);
286 fprintf(foutput
, "%s", tags
[token_translations
[i
]]);
288 sprintf (buffer
, " (%d)", i
);
290 for (j
= 1; j
<= nrules
; j
++)
292 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
293 if (*rule
== token_translations
[i
])
296 sprintf (buffer
+ strlen(buffer
), " %d", j
);
300 fprintf (foutput
, "%s\n", buffer
);
304 for (i
= 1; i
< ntokens
; i
++)
307 column
= strlen (tags
[i
]);
308 fprintf(foutput
, "%s", tags
[i
]);
310 sprintf (buffer
, " (%d)", i
);
312 for (j
= 1; j
<= nrules
; j
++)
314 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
318 sprintf (buffer
+ strlen(buffer
), " %d", j
);
322 fprintf (foutput
, "%s\n", buffer
);
325 fputs(_("\nNonterminals, with rules where they appear\n\n"), foutput
);
326 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
328 int left_count
= 0, right_count
= 0;
330 for (j
= 1; j
<= nrules
; j
++)
334 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
343 fprintf(foutput
, "%s", tags
[i
]);
344 column
= strlen (tags
[i
]);
345 sprintf (buffer
, " (%d)", i
);
351 sprintf (buffer
+ strlen(buffer
), _(" on left:"));
353 for (j
= 1; j
<= nrules
; j
++)
357 sprintf (buffer
+ strlen(buffer
), " %d", j
);
364 sprintf (buffer
+ strlen(buffer
), ",");
366 sprintf (buffer
+ strlen(buffer
), _(" on right:"));
367 for (j
= 1; j
<= nrules
; j
++)
369 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
373 sprintf (buffer
+ strlen(buffer
), " %d", j
);
378 fprintf (foutput
, "%s\n", buffer
);