1 /* $OpenBSD: error.c,v 1.14 2014/03/08 01:05:39 tedu Exp $ */
2 /* $NetBSD: error.c,v 1.4 1996/03/19 03:21:32 jtc Exp $ */
5 * Copyright (c) 1989 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 /* routines for printing error messages */
44 fprintf(stderr
, "%s: %s\n", input_file_name
, msg
);
52 fprintf(stderr
, "%s: yacc is out of space\n", input_file_name
);
58 open_error(char *filename
)
60 fprintf(stderr
, "%s: cannot open source file %s\n",
61 input_file_name
, filename
);
66 open_write_error(char *filename
)
68 fprintf(stderr
, "%s: cannot open target file %s for writing\n",
69 input_file_name
, filename
);
76 fprintf(stderr
, "%s:%d: unexpected end-of-file\n",
77 input_file_name
, lineno
);
83 print_pos(char *st_line
, char *st_cptr
)
89 for (s
= st_line
; *s
!= '\n'; ++s
) {
90 if (isprint((unsigned char)*s
) || *s
== '\t')
96 for (s
= st_line
; s
< st_cptr
; ++s
) {
107 syntax_error(int st_lineno
, char *st_line
, char *st_cptr
)
109 fprintf(stderr
, "%s:%d: syntax error\n",
110 input_file_name
, st_lineno
);
111 print_pos(st_line
, st_cptr
);
116 unterminated_comment(int c_lineno
, char *c_line
, char *c_cptr
)
118 fprintf(stderr
, "%s:%d: unmatched /*\n",
119 input_file_name
, c_lineno
);
120 print_pos(c_line
, c_cptr
);
125 unterminated_string(int s_lineno
, char *s_line
, char *s_cptr
)
127 fprintf(stderr
, "%s:%d:, unterminated string\n",
128 input_file_name
, s_lineno
);
129 print_pos(s_line
, s_cptr
);
134 unterminated_text(int t_lineno
, char *t_line
, char *t_cptr
)
136 fprintf(stderr
, "%s:%d: unmatched %%{\n",
137 input_file_name
, t_lineno
);
138 print_pos(t_line
, t_cptr
);
143 unterminated_union(int u_lineno
, char *u_line
, char *u_cptr
)
145 fprintf(stderr
, "%s:%d: unterminated %%union declaration\n",
146 input_file_name
, u_lineno
);
147 print_pos(u_line
, u_cptr
);
152 over_unionized(char *u_cptr
)
154 fprintf(stderr
, "%s:%d: too many %%union declarations\n",
155 input_file_name
, lineno
);
156 print_pos(line
, u_cptr
);
161 illegal_tag(int t_lineno
, char *t_line
, char *t_cptr
)
163 fprintf(stderr
, "%s:%d: illegal tag\n",
164 input_file_name
, t_lineno
);
165 print_pos(t_line
, t_cptr
);
171 illegal_character(char *c_cptr
)
173 fprintf(stderr
, "%s:%d: illegal character\n",
174 input_file_name
, lineno
);
175 print_pos(line
, c_cptr
);
181 used_reserved(char *s
)
183 fprintf(stderr
, "%s:%d: illegal use of reserved symbol %s\n",
184 input_file_name
, lineno
, s
);
189 tokenized_start(char *s
)
191 fprintf(stderr
, "%s:%d: the start symbol %s cannot be declared to be a token\n",
192 input_file_name
, lineno
, s
);
197 retyped_warning(char *s
)
199 fprintf(stderr
, "%s:%d: the type of %s has been redeclared\n",
200 input_file_name
, lineno
, s
);
204 reprec_warning(char *s
)
206 fprintf(stderr
, "%s:%d: the precedence of %s has been redeclared\n",
207 input_file_name
, lineno
, s
);
211 revalued_warning(char *s
)
213 fprintf(stderr
, "%s:%d: the value of %s has been redeclared\n",
214 input_file_name
, lineno
, s
);
218 terminal_start(char *s
)
220 fprintf(stderr
, "%s:%d: the start symbol %s is a token\n",
221 input_file_name
, lineno
, s
);
226 restarted_warning(void)
228 fprintf(stderr
, "%s:%d: the start symbol has been redeclared\n",
229 input_file_name
, lineno
);
235 fprintf(stderr
, "%s:%d: no grammar has been specified\n",
236 input_file_name
, lineno
);
241 terminal_lhs(int s_lineno
)
243 fprintf(stderr
, "%s:%d: a token appears on the lhs of a production\n",
244 input_file_name
, s_lineno
);
249 prec_redeclared(void)
251 fprintf(stderr
, "%s:%d: conflicting %%prec specifiers\n",
252 input_file_name
, lineno
);
256 unterminated_action(int a_lineno
, char *a_line
, char *a_cptr
)
258 fprintf(stderr
, "%s:%d: unterminated action\n",
259 input_file_name
, a_lineno
);
260 print_pos(a_line
, a_cptr
);
265 dollar_warning(int a_lineno
, int i
)
267 fprintf(stderr
, "%s:%d: $%d references beyond the end of the current rule\n",
268 input_file_name
, a_lineno
, i
);
272 dollar_error(int a_lineno
, char *a_line
, char *a_cptr
)
274 fprintf(stderr
, "%s:%d: illegal $-name\n",
275 input_file_name
, a_lineno
);
276 print_pos(a_line
, a_cptr
);
284 fprintf(stderr
, "%s:%d: $$ is untyped\n",
285 input_file_name
, lineno
);
290 untyped_rhs(int i
, char *s
)
292 fprintf(stderr
, "%s:%d: $%d (%s) is untyped\n",
293 input_file_name
, lineno
, i
, s
);
300 fprintf(stderr
, "%s:%d: $%d is untyped\n",
301 input_file_name
, lineno
, i
);
306 default_action_warning(void)
308 fprintf(stderr
, "%s:%d: the default action assigns an undefined value to $$\n",
309 input_file_name
, lineno
);
313 undefined_goal(char *s
)
315 fprintf(stderr
, "%s: the start symbol %s is undefined\n", input_file_name
, s
);
320 undefined_symbol_warning(char *s
)
322 fprintf(stderr
, "%s: the symbol %s is undefined\n", input_file_name
, s
);