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 $
40 /* routines for printing error messages */
45 static void print_pos(const char *, const char *);
48 fatal(const char *msg)
50 errx(2, "f - %s", msg);
57 errx(2, "f - out of space");
62 open_error(const char *filename)
64 errx(2, "f - cannot open \"%s\"", filename);
71 errx(1, "e - line %d of \"%s\", unexpected end-of-file",
72 lineno, input_file_name);
77 print_pos(const char *st_line, const char *st_cptr)
81 if (st_line == NULL) return;
82 for (s = st_line; *s != '\n'; ++s)
84 if (isprint(*s) || *s == '\t')
90 for (s = st_line; s < st_cptr; ++s)
103 syntax_error(int st_lineno, const char *st_line, const char *st_cptr)
105 warnx("e - line %d of \"%s\", syntax error",
106 st_lineno, input_file_name);
107 print_pos(st_line, st_cptr);
113 unterminated_comment(int c_lineno, const char *c_line, const char *c_cptr)
115 warnx("e - line %d of \"%s\", unmatched /*",
116 c_lineno, input_file_name);
117 print_pos(c_line, c_cptr);
123 unterminated_string(int s_lineno, const char *s_line, const char *s_cptr)
125 warnx("e - line %d of \"%s\", unterminated string",
126 s_lineno, input_file_name);
127 print_pos(s_line, s_cptr);
133 unterminated_text(int t_lineno, const char *t_line, const char *t_cptr)
135 warnx("e - line %d of \"%s\", unmatched %%{",
136 t_lineno, input_file_name);
137 print_pos(t_line, t_cptr);
143 unterminated_union(int u_lineno, const char *u_line, const char *u_cptr)
145 warnx("e - line %d of \"%s\", unterminated %%union declaration",
146 u_lineno, input_file_name);
147 print_pos(u_line, u_cptr);
153 over_unionized(const char *u_cptr)
155 warnx("e - line %d of \"%s\", too many %%union declarations",
156 lineno, input_file_name);
157 print_pos(line, u_cptr);
163 illegal_tag(int t_lineno, const char *t_line, const char *t_cptr)
165 warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
166 print_pos(t_line, t_cptr);
172 illegal_character(const char *c_cptr)
174 warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
175 print_pos(line, c_cptr);
181 used_reserved(const char *s)
183 errx(1, "e - line %d of \"%s\", illegal use of reserved symbol %s",
184 lineno, input_file_name, s);
189 tokenized_start(const char *s)
191 errx(1, "e - line %d of \"%s\", the start symbol %s cannot be \
192 declared to be a token", lineno, input_file_name, s);
197 retyped_warning(const char *s)
199 warnx("w - line %d of \"%s\", the type of %s has been redeclared",
200 lineno, input_file_name, s);
205 reprec_warning(const char *s)
207 warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
208 lineno, input_file_name, s);
213 revalued_warning(const char *s)
215 warnx("w - line %d of \"%s\", the value of %s has been redeclared",
216 lineno, input_file_name, s);
221 terminal_start(const char *s)
223 errx(1, "e - line %d of \"%s\", the start symbol %s is a token",
224 lineno, input_file_name, s);
229 restarted_warning(void)
231 warnx("w - line %d of \"%s\", the start symbol has been redeclared",
232 lineno, input_file_name);
239 errx(1, "e - line %d of \"%s\", no grammar has been specified",
240 lineno, input_file_name);
245 terminal_lhs(int s_lineno)
247 errx(1, "e - line %d of \"%s\", a token appears on the lhs of a production",
248 s_lineno, input_file_name);
253 prec_redeclared(void)
255 warnx("w - line %d of \"%s\", conflicting %%prec specifiers",
256 lineno, input_file_name);
261 unterminated_action(int a_lineno, const char *a_line, const char *a_cptr)
263 warnx("e - line %d of \"%s\", unterminated action",
264 a_lineno, input_file_name);
265 print_pos(a_line, a_cptr);
270 dollar_warning(int a_lineno, int i)
272 warnx("w - line %d of \"%s\", $%d references beyond the \
273 end of the current rule", a_lineno, input_file_name, i);
278 dollar_error(int a_lineno, const char *a_line, const char *a_cptr)
280 warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
281 print_pos(a_line, a_cptr);
289 errx(1, "e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
294 untyped_rhs(int i, const char *s)
296 errx(1, "e - line %d of \"%s\", $%d (%s) is untyped",
297 lineno, input_file_name, i, s);
304 errx(1, "e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
309 default_action_warning(void)
311 warnx("w - line %d of \"%s\", the default action assigns an \
312 undefined value to $$", lineno, input_file_name);
317 undefined_goal(const char *s)
319 errx(1, "e - the start symbol %s is undefined", s);
324 undefined_symbol_warning(const char *s)
326 warnx("w - the symbol %s is undefined", s);