]>
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
32 extern short *accessing_symbol
;
33 extern core
**state_table
;
34 extern shifts
**shift_table
;
35 extern errs
**err_table
;
36 extern reductions
**reduction_table
;
37 extern char *consistent
;
38 extern char any_conflicts
;
39 extern char *conflicts
;
40 extern int final_state
;
42 extern void conflict_log
PARAMS((void));
43 extern void verbose_conflict_log
PARAMS((void));
44 extern void print_reductions
PARAMS((int));
46 void terse
PARAMS((void));
47 void verbose
PARAMS((void));
48 void print_token
PARAMS((int, int));
49 void print_state
PARAMS((int));
50 void print_core
PARAMS((int));
51 void print_actions
PARAMS((int));
52 void print_grammar
PARAMS((void));
70 verbose_conflict_log();
74 for (i
= 0; i
< nstates
; i
++)
82 print_token (int extnum
, int token
)
84 fprintf(foutput
, _(" type %d is %s\n"), extnum
, tags
[token
]);
89 print_state (int state
)
91 fprintf(foutput
, _("\n\nstate %d\n\n"), state
);
98 print_core (int state
)
103 register core
*statep
;
107 statep
= state_table
[state
];
112 for (i
= 0; i
< k
; i
++)
114 sp1
= sp
= ritem
+ statep
->items
[i
];
120 fprintf(foutput
, " %s -> ", tags
[rlhs
[rule
]]);
122 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
124 fprintf(foutput
, "%s ", tags
[*sp
]);
131 fprintf(foutput
, " %s", tags
[*sp
]);
135 fprintf (foutput
, _(" (rule %d)"), rule
);
144 print_actions (int state
)
150 register shifts
*shiftp
;
152 register reductions
*redp
;
155 shiftp
= shift_table
[state
];
156 redp
= reduction_table
[state
];
157 errp
= err_table
[state
];
159 if (!shiftp
&& !redp
)
161 if (final_state
== state
)
162 fprintf(foutput
, _(" $default\taccept\n"));
164 fprintf(foutput
, _(" NO ACTIONS\n"));
172 for (i
= 0; i
< k
; i
++)
174 if (! shiftp
->shifts
[i
]) continue;
175 state1
= shiftp
->shifts
[i
];
176 symbol
= accessing_symbol
[state1
];
177 /* The following line used to be turned off. */
178 if (ISVAR(symbol
)) break;
179 if (symbol
==0) /* I.e. strcmp(tags[symbol],"$")==0 */
180 fprintf(foutput
, _(" $ \tgo to state %d\n"), state1
);
182 fprintf(foutput
, _(" %-4s\tshift, and go to state %d\n"),
183 tags
[symbol
], state1
);
201 for (j
= 0; j
< nerrs
; j
++)
203 if (! errp
->errs
[j
]) continue;
204 symbol
= errp
->errs
[j
];
205 fprintf(foutput
, _(" %-4s\terror (nonassociative)\n"), tags
[symbol
]);
212 if (consistent
[state
] && redp
)
214 rule
= redp
->rules
[0];
216 fprintf(foutput
, _(" $default\treduce using rule %d (%s)\n\n"),
221 print_reductions(state
);
228 if (! shiftp
->shifts
[i
]) continue;
229 state1
= shiftp
->shifts
[i
];
230 symbol
= accessing_symbol
[state1
];
231 fprintf(foutput
, _(" %-4s\tgo to state %d\n"), tags
[symbol
], state1
);
238 #define END_TEST(end) \
239 if (column + strlen(buffer) > (end)) \
240 { fprintf (foutput, "%s\n ", buffer); column = 3; buffer[0] = 0; } \
251 /* rule # : LHS -> RHS */
252 fputs(_("\nGrammar\n"), foutput
);
253 for (i
= 1; i
<= nrules
; i
++)
254 /* Don't print rules disabled in reduce_grammar_tables. */
257 fprintf(foutput
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
258 rule
= &ritem
[rrhs
[i
]];
261 fprintf(foutput
, " %s", tags
[*rule
++]);
263 fputs (_(" /* empty */"), foutput
);
267 /* TERMINAL (type #) : rule #s terminal is on RHS */
268 fputs(_("\nTerminals, with rules where they appear\n\n"), foutput
);
269 fprintf(foutput
, "%s (-1)\n", tags
[0]);
272 for (i
= 0; i
<= max_user_token_number
; i
++)
273 if (token_translations
[i
] != 2)
276 column
= strlen (tags
[token_translations
[i
]]);
277 fprintf(foutput
, "%s", tags
[token_translations
[i
]]);
279 sprintf (buffer
, " (%d)", i
);
281 for (j
= 1; j
<= nrules
; j
++)
283 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
284 if (*rule
== token_translations
[i
])
287 sprintf (buffer
+ strlen(buffer
), " %d", j
);
291 fprintf (foutput
, "%s\n", buffer
);
295 for (i
= 1; i
< ntokens
; i
++)
298 column
= strlen (tags
[i
]);
299 fprintf(foutput
, "%s", tags
[i
]);
301 sprintf (buffer
, " (%d)", i
);
303 for (j
= 1; j
<= nrules
; j
++)
305 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
309 sprintf (buffer
+ strlen(buffer
), " %d", j
);
313 fprintf (foutput
, "%s\n", buffer
);
316 fputs(_("\nNonterminals, with rules where they appear\n\n"), foutput
);
317 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
319 int left_count
= 0, right_count
= 0;
321 for (j
= 1; j
<= nrules
; j
++)
325 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
334 fprintf(foutput
, "%s", tags
[i
]);
335 column
= strlen (tags
[i
]);
336 sprintf (buffer
, " (%d)", i
);
342 sprintf (buffer
+ strlen(buffer
), _(" on left:"));
344 for (j
= 1; j
<= nrules
; j
++)
348 sprintf (buffer
+ strlen(buffer
), " %d", j
);
355 sprintf (buffer
+ strlen(buffer
), ",");
357 sprintf (buffer
+ strlen(buffer
), _(" on right:"));
358 for (j
= 1; j
<= nrules
; j
++)
360 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
364 sprintf (buffer
+ strlen(buffer
), " %d", j
);
369 fprintf (foutput
, "%s\n", buffer
);