]>
git.saurik.com Git - bison.git/blob - src/print.c
061a0fee9aa2d96ec37d448d018b88c68436e1b0
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"
32 extern int final_state
;
34 extern void terse
PARAMS ((void));
35 extern void verbose
PARAMS ((void));
37 #if 0 /* XXX currently unused. */
38 static void print_token
PARAMS ((int, int));
41 static void print_state
PARAMS ((int));
42 static void print_core
PARAMS ((int));
43 static void print_actions
PARAMS ((int));
44 static void print_grammar
PARAMS ((void));
64 for (i
= 0; i
< nstates
; i
++)
69 #if 0 /* XXX currently unused. */
71 print_token (int extnum
, int token
)
73 fprintf (foutput
, _(" type %d is %s\n"), extnum
, tags
[token
]);
79 print_state (int state
)
81 fprintf (foutput
, _("\n\nstate %d\n\n"), state
);
83 print_actions (state
);
88 print_core (int state
)
97 statep
= state_table
[state
];
103 for (i
= 0; i
< k
; i
++)
105 sp1
= sp
= ritem
+ statep
->items
[i
];
111 fprintf (foutput
, " %s -> ", tags
[rlhs
[rule
]]);
113 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
115 fprintf (foutput
, "%s ", tags
[*sp
]);
122 fprintf (foutput
, " %s", tags
[*sp
]);
126 fprintf (foutput
, _(" (rule %d)"), rule
);
127 putc ('\n', foutput
);
130 putc ('\n', foutput
);
135 print_actions (int state
)
146 shiftp
= shift_table
[state
];
147 redp
= reduction_table
[state
];
148 errp
= err_table
[state
];
150 if (!shiftp
&& !redp
)
152 if (final_state
== state
)
153 fprintf (foutput
, _(" $default\taccept\n"));
155 fprintf (foutput
, _(" NO ACTIONS\n"));
163 for (i
= 0; i
< k
; i
++)
165 if (!shiftp
->shifts
[i
])
167 state1
= shiftp
->shifts
[i
];
168 symbol
= accessing_symbol
[state1
];
169 /* The following line used to be turned off. */
172 if (symbol
== 0) /* I.e. strcmp(tags[symbol],"$")==0 */
173 fprintf (foutput
, _(" $ \tgo to state %d\n"), state1
);
175 fprintf (foutput
, _(" %-4s\tshift, and go to state %d\n"),
176 tags
[symbol
], state1
);
180 putc ('\n', foutput
);
194 for (j
= 0; j
< nerrs
; j
++)
198 symbol
= errp
->errs
[j
];
199 fprintf (foutput
, _(" %-4s\terror (nonassociative)\n"),
204 putc ('\n', foutput
);
207 if (consistent
[state
] && redp
)
209 rule
= redp
->rules
[0];
211 fprintf (foutput
, _(" $default\treduce using rule %d (%s)\n\n"),
216 print_reductions (state
);
223 if (!shiftp
->shifts
[i
])
225 state1
= shiftp
->shifts
[i
];
226 symbol
= accessing_symbol
[state1
];
227 fprintf (foutput
, _(" %-4s\tgo to state %d\n"), tags
[symbol
],
231 putc ('\n', foutput
);
235 #define END_TEST(end) \
237 if (column + strlen(buffer) > (end)) { \
238 fprintf (foutput, "%s\n ", buffer); \
252 /* rule # : LHS -> RHS */
253 fputs (_("\nGrammar\n"), foutput
);
254 for (i
= 1; i
<= nrules
; i
++)
255 /* Don't print rules disabled in reduce_grammar_tables. */
258 fprintf (foutput
, _("rule %-4d %s ->"), i
, tags
[rlhs
[i
]]);
259 rule
= &ritem
[rrhs
[i
]];
262 fprintf (foutput
, " %s", tags
[*rule
++]);
264 fputs (_(" /* empty */"), foutput
);
265 putc ('\n', foutput
);
268 /* TERMINAL (type #) : rule #s terminal is on RHS */
269 fputs (_("\nTerminals, with rules where they appear\n\n"), foutput
);
270 fprintf (foutput
, "%s (-1)\n", tags
[0]);
273 for (i
= 0; i
<= max_user_token_number
; i
++)
274 if (token_translations
[i
] != 2)
277 column
= strlen (tags
[token_translations
[i
]]);
278 fprintf (foutput
, "%s", tags
[token_translations
[i
]]);
280 sprintf (buffer
, " (%d)", i
);
282 for (j
= 1; j
<= nrules
; j
++)
284 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
285 if (*rule
== token_translations
[i
])
288 sprintf (buffer
+ strlen (buffer
), " %d", j
);
292 fprintf (foutput
, "%s\n", buffer
);
296 for (i
= 1; i
< ntokens
; i
++)
299 column
= strlen (tags
[i
]);
300 fprintf (foutput
, "%s", tags
[i
]);
302 sprintf (buffer
, " (%d)", i
);
304 for (j
= 1; j
<= nrules
; j
++)
306 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
310 sprintf (buffer
+ strlen (buffer
), " %d", j
);
314 fprintf (foutput
, "%s\n", buffer
);
317 fputs (_("\nNonterminals, with rules where they appear\n\n"), foutput
);
318 for (i
= ntokens
; i
<= nsyms
- 1; i
++)
320 int left_count
= 0, right_count
= 0;
322 for (j
= 1; j
<= nrules
; j
++)
326 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
335 fprintf (foutput
, "%s", tags
[i
]);
336 column
= strlen (tags
[i
]);
337 sprintf (buffer
, " (%d)", i
);
343 sprintf (buffer
+ strlen (buffer
), _(" on left:"));
345 for (j
= 1; j
<= nrules
; j
++)
349 sprintf (buffer
+ strlen (buffer
), " %d", j
);
356 sprintf (buffer
+ strlen (buffer
), ",");
358 sprintf (buffer
+ strlen (buffer
), _(" on right:"));
359 for (j
= 1; j
<= nrules
; j
++)
361 for (rule
= &ritem
[rrhs
[j
]]; *rule
> 0; rule
++)
365 sprintf (buffer
+ strlen (buffer
), " %d", j
);
370 fprintf (foutput
, "%s\n", buffer
);