]>
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();
43 extern void verbose_conflict_log();
44 extern void print_reductions();
68 verbose_conflict_log();
72 for (i
= 0; i
< nstates
; i
++)
80 print_token(extnum
, token
)
83 fprintf(foutput
, " type %d is %s\n", extnum
, tags
[token
]);
91 fprintf(foutput
, "\n\nstate %d\n\n", state
);
104 register core
*statep
;
108 statep
= state_table
[state
];
113 for (i
= 0; i
< k
; i
++)
115 sp1
= sp
= ritem
+ statep
->items
[i
];
121 fprintf(foutput
, " %s -> ", tags
[rlhs
[rule
]]);
123 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
125 fprintf(foutput
, "%s ", tags
[*sp
]);
132 fprintf(foutput
, " %s", tags
[*sp
]);
136 fprintf (foutput
, " (rule %d)", rule
);
152 register shifts
*shiftp
;
154 register reductions
*redp
;
157 shiftp
= shift_table
[state
];
158 redp
= reduction_table
[state
];
159 errp
= err_table
[state
];
161 if (!shiftp
&& !redp
)
163 if (final_state
== state
)
164 fprintf(foutput
, " $default\taccept\n");
166 fprintf(foutput
, " NO ACTIONS\n");
174 for (i
= 0; i
< k
; i
++)
176 if (! shiftp
->shifts
[i
]) continue;
177 state1
= shiftp
->shifts
[i
];
178 symbol
= accessing_symbol
[state1
];
179 /* The following line used to be turned off. */
180 if (ISVAR(symbol
)) break;
181 if (symbol
==0) /* I.e. strcmp(tags[symbol],"$")==0 */
182 fprintf(foutput
, " $ \tgo to state %d\n", state1
);
184 fprintf(foutput
, " %-4s\tshift, and go to state %d\n",
185 tags
[symbol
], state1
);
203 for (j
= 0; j
< nerrs
; j
++)
205 if (! errp
->errs
[j
]) continue;
206 symbol
= errp
->errs
[j
];
207 fprintf(foutput
, " %-4s\terror (nonassociative)\n", tags
[symbol
]);
214 if (consistent
[state
] && redp
)
216 rule
= redp
->rules
[0];
218 fprintf(foutput
, " $default\treduce using rule %d (%s)\n\n",
223 print_reductions(state
);
230 if (! shiftp
->shifts
[i
]) continue;
231 state1
= shiftp
->shifts
[i
];
232 symbol
= accessing_symbol
[state1
];
233 fprintf(foutput
, " %-4s\tgo to state %d\n", tags
[symbol
], state1
);
240 #define END_TEST(end) \
241 if (column + strlen(buffer) > (end)) \
242 { fprintf (foutput, "%s\n ", buffer); column = 3; buffer[0] = 0; } \
253 /* rule # : LHS -> RHS */
254 fputs("\nGrammar\n", foutput
);
255 for (i
= 1; i
<= nrules
; i
++)
256 /* Don't print rules disabled in reduce_grammar_tables. */
259 fprintf(foutput
, "rule %-4d %s ->", i
, tags
[rlhs
[i
]]);
260 rule
= &ritem
[rrhs
[i
]];
263 fprintf(foutput
, " %s", tags
[*rule
++]);
265 fputs (" /* empty */", foutput
);
269 /* TERMINAL (type #) : rule #s terminal is on RHS */
270 fputs("\nTerminals, with rules where they appear\n\n", foutput
);
271 fprintf(foutput
, "%s (-1)\n", tags
[0]);
274 for (i
= 0; i
<= max_user_token_number
; i
++)
275 if (token_translations
[i
] != 2)
278 column
= strlen (tags
[token_translations
[i
]]);
279 fprintf(foutput
, "%s", tags
[token_translations
[i
]]);
281 sprintf (buffer
, " (%d)", i
);
283 for (j
= 1; j
<= nrules
; j
++)
285 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
286 if (*rule
== token_translations
[i
])
289 sprintf (buffer
+ strlen(buffer
), " %d", j
);
293 fprintf (foutput
, "%s\n", buffer
);
297 for (i
= 1; i
< ntokens
; i
++)
300 column
= strlen (tags
[i
]);
301 fprintf(foutput
, "%s", tags
[i
]);
303 sprintf (buffer
, " (%d)", i
);
305 for (j
= 1; j
<= nrules
; j
++)
307 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
311 sprintf (buffer
+ strlen(buffer
), " %d", j
);
315 fprintf (foutput
, "%s\n", buffer
);
318 fputs("\nNonterminals, with rules where they appear\n\n", foutput
);
319 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
321 int left_count
= 0, right_count
= 0;
323 for (j
= 1; j
<= nrules
; j
++)
327 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
336 fprintf(foutput
, "%s", tags
[i
]);
337 column
= strlen (tags
[i
]);
338 sprintf (buffer
, " (%d)", i
);
344 sprintf (buffer
+ strlen(buffer
), " on left:");
346 for (j
= 1; j
<= nrules
; j
++)
350 sprintf (buffer
+ strlen(buffer
), " %d", j
);
357 sprintf (buffer
+ strlen(buffer
), ",");
359 sprintf (buffer
+ strlen(buffer
), " on right:");
360 for (j
= 1; j
<= nrules
; j
++)
362 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
366 sprintf (buffer
+ strlen(buffer
), " %d", j
);
371 fprintf (foutput
, "%s\n", buffer
);