1 /* $NetBSD: error.c,v 1.10 2006/05/24 18:01:43 christos Exp $ */
4 * Copyright (c) 1989 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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
35 #include <sys/cdefs.h>
36 #if defined(__RCSID) && !defined(lint)
38 static char sccsid
[] = "@(#)error.c 5.3 (Berkeley) 6/1/90";
40 __RCSID("$NetBSD: error.c,v 1.10 2006/05/24 18:01:43 christos Exp $");
44 /* routines for printing error messages */
49 fatal(const char *msg
)
51 fprintf(stderr
, "%s: f - %s\n", myname
, msg
);
59 fprintf(stderr
, "%s: f - out of space\n", myname
);
64 open_error(const char *filename
)
66 fprintf(stderr
, "%s: f - cannot open \"%s\"\n", myname
, filename
);
73 fprintf(stderr
, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
74 myname
, lineno
, input_file_name
);
79 print_pos(char *st_line
, char *st_cptr
)
83 if (st_line
== 0) return;
84 for (s
= st_line
; *s
!= '\n'; ++s
)
86 if (isprint((unsigned char)*s
) || *s
== '\t')
92 for (s
= st_line
; s
< st_cptr
; ++s
)
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
230 fprintf(stderr
, "%s: e - line %d of \"%s\", no grammar has been \
231 specified\n", myname
, lineno
, input_file_name
);
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
);
244 prec_redeclared(void)
246 fprintf(stderr
, "%s: w - line %d of \"%s\", conflicting %%prec \
247 specifiers\n", myname
, lineno
, input_file_name
);
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
);
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
);
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
);
278 fprintf(stderr
, "%s: e - line %d of \"%s\", $$ is untyped\n",
279 myname
, lineno
, input_file_name
);
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
);
294 fprintf(stderr
, "%s: e - line %d of \"%s\", $%d is untyped\n",
295 myname
, lineno
, input_file_name
, i
);
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
);
307 undefined_goal(char *s
)
309 fprintf(stderr
, "%s: e - the start symbol %s is undefined\n", myname
, s
);
314 undefined_symbol_warning(char *s
)
316 fprintf(stderr
, "%s: w - the symbol %s is undefined\n", myname
, s
);