2 * Copyright (c) 1989 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)error.c 5.3 (Berkeley) 6/1/90
37 * $FreeBSD: src/usr.bin/yacc/error.c,v 1.7 1999/08/28 01:07:59 peter Exp $
38 * $DragonFly: src/usr.bin/yacc/error.c,v 1.5 2005/01/05 15:26:05 joerg Exp $
41 /* routines for printing error messages */
46 static void print_pos(const char *, const char *);
49 fatal(const char *msg
)
51 errx(2, "f - %s", msg
);
58 errx(2, "f - out of space");
63 open_error(const char *filename
)
65 errx(2, "f - cannot open \"%s\"", filename
);
72 errx(1, "e - line %d of \"%s\", unexpected end-of-file",
73 lineno
, input_file_name
);
78 print_pos(const char *st_line
, const char *st_cptr
)
82 if (st_line
== 0) return;
83 for (s
= st_line
; *s
!= '\n'; ++s
)
85 if (isprint(*s
) || *s
== '\t')
91 for (s
= st_line
; s
< st_cptr
; ++s
)
104 syntax_error(int st_lineno
, const char *st_line
, const char *st_cptr
)
106 warnx("e - line %d of \"%s\", syntax error",
107 st_lineno
, input_file_name
);
108 print_pos(st_line
, st_cptr
);
114 unterminated_comment(int c_lineno
, const char *c_line
, const char *c_cptr
)
116 warnx("e - line %d of \"%s\", unmatched /*",
117 c_lineno
, input_file_name
);
118 print_pos(c_line
, c_cptr
);
124 unterminated_string(int s_lineno
, const char *s_line
, const char *s_cptr
)
126 warnx("e - line %d of \"%s\", unterminated string",
127 s_lineno
, input_file_name
);
128 print_pos(s_line
, s_cptr
);
134 unterminated_text(int t_lineno
, const char *t_line
, const char *t_cptr
)
136 warnx("e - line %d of \"%s\", unmatched %%{",
137 t_lineno
, input_file_name
);
138 print_pos(t_line
, t_cptr
);
144 unterminated_union(int u_lineno
, const char *u_line
, const char *u_cptr
)
146 warnx("e - line %d of \"%s\", unterminated %%union declaration",
147 u_lineno
, input_file_name
);
148 print_pos(u_line
, u_cptr
);
154 over_unionized(const char *u_cptr
)
156 warnx("e - line %d of \"%s\", too many %%union declarations",
157 lineno
, input_file_name
);
158 print_pos(line
, u_cptr
);
164 illegal_tag(int t_lineno
, const char *t_line
, const char *t_cptr
)
166 warnx("e - line %d of \"%s\", illegal tag", t_lineno
, input_file_name
);
167 print_pos(t_line
, t_cptr
);
173 illegal_character(const char *c_cptr
)
175 warnx("e - line %d of \"%s\", illegal character", lineno
, input_file_name
);
176 print_pos(line
, c_cptr
);
182 used_reserved(const char *s
)
184 errx(1, "e - line %d of \"%s\", illegal use of reserved symbol %s",
185 lineno
, input_file_name
, s
);
190 tokenized_start(const char *s
)
192 errx(1, "e - line %d of \"%s\", the start symbol %s cannot be \
193 declared to be a token", lineno
, input_file_name
, s
);
198 retyped_warning(const char *s
)
200 warnx("w - line %d of \"%s\", the type of %s has been redeclared",
201 lineno
, input_file_name
, s
);
206 reprec_warning(const char *s
)
208 warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
209 lineno
, input_file_name
, s
);
214 revalued_warning(const char *s
)
216 warnx("w - line %d of \"%s\", the value of %s has been redeclared",
217 lineno
, input_file_name
, s
);
222 terminal_start(const char *s
)
224 errx(1, "e - line %d of \"%s\", the start symbol %s is a token",
225 lineno
, input_file_name
, s
);
230 restarted_warning(void)
232 warnx("w - line %d of \"%s\", the start symbol has been redeclared",
233 lineno
, input_file_name
);
240 errx(1, "e - line %d of \"%s\", no grammar has been specified",
241 lineno
, input_file_name
);
246 terminal_lhs(int s_lineno
)
248 errx(1, "e - line %d of \"%s\", a token appears on the lhs of a production",
249 s_lineno
, input_file_name
);
254 prec_redeclared(void)
256 warnx("w - line %d of \"%s\", conflicting %%prec specifiers",
257 lineno
, input_file_name
);
262 unterminated_action(int a_lineno
, const char *a_line
, const char *a_cptr
)
264 warnx("e - line %d of \"%s\", unterminated action",
265 a_lineno
, input_file_name
);
266 print_pos(a_line
, a_cptr
);
271 dollar_warning(int a_lineno
, int i
)
273 warnx("w - line %d of \"%s\", $%d references beyond the \
274 end of the current rule", a_lineno
, input_file_name
, i
);
279 dollar_error(int a_lineno
, const char *a_line
, const char *a_cptr
)
281 warnx("e - line %d of \"%s\", illegal $-name", a_lineno
, input_file_name
);
282 print_pos(a_line
, a_cptr
);
290 errx(1, "e - line %d of \"%s\", $$ is untyped", lineno
, input_file_name
);
295 untyped_rhs(int i
, const char *s
)
297 errx(1, "e - line %d of \"%s\", $%d (%s) is untyped",
298 lineno
, input_file_name
, i
, s
);
305 errx(1, "e - line %d of \"%s\", $%d is untyped", lineno
, input_file_name
, i
);
310 default_action_warning(void)
312 warnx("w - line %d of \"%s\", the default action assigns an \
313 undefined value to $$", lineno
, input_file_name
);
318 undefined_goal(const char *s
)
320 errx(1, "e - the start symbol %s is undefined", s
);
325 undefined_symbol_warning(const char *s
)
327 warnx("w - the symbol %s is undefined", s
);