No empty .Rs/.Re
[netbsd-mini2440.git] / usr.bin / yacc / error.c
blobe9594fc3dc7e00adb97c2c5ba5383f7728336ce8
1 /* $NetBSD: error.c,v 1.10 2006/05/24 18:01:43 christos Exp $ */
3 /*
4 * Copyright (c) 1989 The Regents of the University of California.
5 * All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Robert Paul Corbett.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 #if defined(__RCSID) && !defined(lint)
37 #if 0
38 static char sccsid[] = "@(#)error.c 5.3 (Berkeley) 6/1/90";
39 #else
40 __RCSID("$NetBSD: error.c,v 1.10 2006/05/24 18:01:43 christos Exp $");
41 #endif
42 #endif /* not lint */
44 /* routines for printing error messages */
46 #include "defs.h"
48 __dead void
49 fatal(const char *msg)
51 fprintf(stderr, "%s: f - %s\n", myname, msg);
52 done(2);
56 __dead void
57 no_space(void)
59 fprintf(stderr, "%s: f - out of space\n", myname);
60 done(2);
63 __dead void
64 open_error(const char *filename)
66 fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
67 done(2);
70 __dead void
71 unexpected_EOF(void)
73 fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
74 myname, lineno, input_file_name);
75 done(1);
78 void
79 print_pos(char *st_line, char *st_cptr)
81 char *s;
83 if (st_line == 0) return;
84 for (s = st_line; *s != '\n'; ++s)
86 if (isprint((unsigned char)*s) || *s == '\t')
87 putc(*s, stderr);
88 else
89 putc('?', stderr);
91 putc('\n', stderr);
92 for (s = st_line; s < st_cptr; ++s)
94 if (*s == '\t')
95 putc('\t', stderr);
96 else
97 putc(' ', stderr);
99 putc('^', stderr);
100 putc('\n', stderr);
103 __dead void
104 syntax_error(int st_lineno, char *st_line, char *st_cptr)
106 fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
107 myname, st_lineno, input_file_name);
108 print_pos(st_line, st_cptr);
109 done(1);
112 __dead void
113 unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
115 fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
116 myname, c_lineno, input_file_name);
117 print_pos(c_line, c_cptr);
118 done(1);
121 __dead void
122 unterminated_string(int s_lineno, char *s_line, char *s_cptr)
124 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
125 myname, s_lineno, input_file_name);
126 print_pos(s_line, s_cptr);
127 done(1);
130 __dead void
131 unterminated_text(int t_lineno, char *t_line, char *t_cptr)
133 fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
134 myname, t_lineno, input_file_name);
135 print_pos(t_line, t_cptr);
136 done(1);
139 __dead void
140 unterminated_union(int u_lineno, char *u_line, char *u_cptr)
142 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
143 declaration\n", myname, u_lineno, input_file_name);
144 print_pos(u_line, u_cptr);
145 done(1);
148 __dead void
149 over_unionized(char *u_cptr)
151 fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
152 declarations\n", myname, lineno, input_file_name);
153 print_pos(line, u_cptr);
154 done(1);
157 __dead void
158 illegal_tag(int t_lineno, char *t_line, char *t_cptr)
160 fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
161 myname, t_lineno, input_file_name);
162 print_pos(t_line, t_cptr);
163 done(1);
166 __dead void
167 illegal_character(char *c_cptr)
169 fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
170 myname, lineno, input_file_name);
171 print_pos(line, c_cptr);
172 done(1);
175 __dead void
176 used_reserved(char *s)
178 fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \
179 %s\n", myname, lineno, input_file_name, s);
180 done(1);
183 __dead void
184 tokenized_start(char *s)
186 fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
187 declared to be a token\n", myname, lineno, input_file_name, s);
188 done(1);
191 void
192 retyped_warning(char *s)
194 fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
195 redeclared\n", myname, lineno, input_file_name, s);
198 void
199 reprec_warning(char *s)
201 fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
202 redeclared\n", myname, lineno, input_file_name, s);
205 void
206 revalued_warning(char *s)
208 fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
209 redeclared\n", myname, lineno, input_file_name, s);
212 __dead void
213 terminal_start(char *s)
215 fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
216 token\n", myname, lineno, input_file_name, s);
217 done(1);
220 void
221 restarted_warning(void)
223 fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
224 redeclared\n", myname, lineno, input_file_name);
227 __dead void
228 no_grammar(void)
230 fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
231 specified\n", myname, lineno, input_file_name);
232 done(1);
235 __dead void
236 terminal_lhs(int s_lineno)
238 fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
239 of a production\n", myname, s_lineno, input_file_name);
240 done(1);
243 void
244 prec_redeclared(void)
246 fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \
247 specifiers\n", myname, lineno, input_file_name);
250 __dead void
251 unterminated_action(int a_lineno, char *a_line, char *a_cptr)
253 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
254 myname, a_lineno, input_file_name);
255 print_pos(a_line, a_cptr);
256 done(1);
259 void
260 dollar_warning(int a_lineno, int i)
262 fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
263 end of the current rule\n", myname, a_lineno, input_file_name, i);
266 __dead void
267 dollar_error(int a_lineno, char *a_line, char *a_cptr)
269 fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
270 myname, a_lineno, input_file_name);
271 print_pos(a_line, a_cptr);
272 done(1);
275 __dead void
276 untyped_lhs(void)
278 fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
279 myname, lineno, input_file_name);
280 done(1);
283 __dead void
284 untyped_rhs(int i, char *s)
286 fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
287 myname, lineno, input_file_name, i, s);
288 done(1);
291 __dead void
292 unknown_rhs(int i)
294 fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
295 myname, lineno, input_file_name, i);
296 done(1);
299 void
300 default_action_warning(void)
302 fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
303 undefined value to $$\n", myname, lineno, input_file_name);
306 __dead void
307 undefined_goal(char *s)
309 fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
310 done(1);
313 void
314 undefined_symbol_warning(char *s)
316 fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);