1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Robert Paul Corbett.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 #if 0
34 #ifndef lint
35 static char sccsid[] = "@(#)error.c 5.3 (Berkeley) 6/1/90";
36 #endif
37 #endif
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD: stable/9/usr.bin/yacc/error.c 216370 2010-12-11 08:32:16Z joel $");
40
41 /* routines for printing error messages */
42
43 #include "defs.h"
44
45 static void print_pos(char *, char *);
46
47 void
fatal(const char * msg)48 fatal(const char *msg)
49 {
50 warnx("f - %s", msg);
51 done(2);
52 }
53
54
55 void
no_space(void)56 no_space(void)
57 {
58 warnx("f - out of space");
59 done(2);
60 }
61
62
63 void
open_error(const char * filename)64 open_error(const char *filename)
65 {
66 warnx("f - cannot open \"%s\"", filename);
67 done(2);
68 }
69
70
71 void
unexpected_EOF(void)72 unexpected_EOF(void)
73 {
74 warnx("e - line %d of \"%s\", unexpected end-of-file",
75 lineno, input_file_name);
76 done(1);
77 }
78
79
80 static void
print_pos(char * st_line,char * st_cptr)81 print_pos(char *st_line, char *st_cptr)
82 {
83 char *s;
84
85 if (st_line == 0) return;
86 for (s = st_line; *s != '\n'; ++s)
87 {
88 if (isprint(*s) || *s == '\t')
89 putc(*s, stderr);
90 else
91 putc('?', stderr);
92 }
93 putc('\n', stderr);
94 for (s = st_line; s < st_cptr; ++s)
95 {
96 if (*s == '\t')
97 putc('\t', stderr);
98 else
99 putc(' ', stderr);
100 }
101 putc('^', stderr);
102 putc('\n', stderr);
103 }
104
105
106 void
syntax_error(int st_lineno,char * st_line,char * st_cptr)107 syntax_error(int st_lineno, char *st_line, char *st_cptr)
108 {
109 warnx("e - line %d of \"%s\", syntax error",
110 st_lineno, input_file_name);
111 print_pos(st_line, st_cptr);
112 done(1);
113 }
114
115
116 void
unterminated_comment(int c_lineno,char * c_line,char * c_cptr)117 unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
118 {
119 warnx("e - line %d of \"%s\", unmatched /*",
120 c_lineno, input_file_name);
121 print_pos(c_line, c_cptr);
122 done(1);
123 }
124
125
126 void
unterminated_string(int s_lineno,char * s_line,char * s_cptr)127 unterminated_string(int s_lineno, char *s_line, char *s_cptr)
128 {
129 warnx("e - line %d of \"%s\", unterminated string",
130 s_lineno, input_file_name);
131 print_pos(s_line, s_cptr);
132 done(1);
133 }
134
135
136 void
unterminated_text(int t_lineno,char * t_line,char * t_cptr)137 unterminated_text(int t_lineno, char *t_line, char *t_cptr)
138 {
139 warnx("e - line %d of \"%s\", unmatched %%{",
140 t_lineno, input_file_name);
141 print_pos(t_line, t_cptr);
142 done(1);
143 }
144
145
146 void
unterminated_union(int u_lineno,char * u_line,char * u_cptr)147 unterminated_union(int u_lineno, char *u_line, char *u_cptr)
148 {
149 warnx("e - line %d of \"%s\", unterminated %%union declaration",
150 u_lineno, input_file_name);
151 print_pos(u_line, u_cptr);
152 done(1);
153 }
154
155
156 void
over_unionized(char * u_cptr)157 over_unionized(char *u_cptr)
158 {
159 warnx("e - line %d of \"%s\", too many %%union declarations",
160 lineno, input_file_name);
161 print_pos(line, u_cptr);
162 done(1);
163 }
164
165
166 void
illegal_tag(int t_lineno,char * t_line,char * t_cptr)167 illegal_tag(int t_lineno, char *t_line, char *t_cptr)
168 {
169 warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
170 print_pos(t_line, t_cptr);
171 done(1);
172 }
173
174
175 void
illegal_character(char * c_cptr)176 illegal_character(char *c_cptr)
177 {
178 warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
179 print_pos(line, c_cptr);
180 done(1);
181 }
182
183
184 void
used_reserved(char * s)185 used_reserved(char *s)
186 {
187 warnx("e - line %d of \"%s\", illegal use of reserved symbol %s",
188 lineno, input_file_name, s);
189 done(1);
190 }
191
192
193 void
tokenized_start(char * s)194 tokenized_start(char *s)
195 {
196 warnx("e - line %d of \"%s\", the start symbol %s cannot be \
197 declared to be a token", lineno, input_file_name, s);
198 done(1);
199 }
200
201
202 void
retyped_warning(char * s)203 retyped_warning(char *s)
204 {
205 warnx("w - line %d of \"%s\", the type of %s has been redeclared",
206 lineno, input_file_name, s);
207 }
208
209
210 void
reprec_warning(char * s)211 reprec_warning(char *s)
212 {
213 warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
214 lineno, input_file_name, s);
215 }
216
217
218 void
revalued_warning(char * s)219 revalued_warning(char *s)
220 {
221 warnx("w - line %d of \"%s\", the value of %s has been redeclared",
222 lineno, input_file_name, s);
223 }
224
225
226 void
terminal_start(char * s)227 terminal_start(char *s)
228 {
229 warnx("e - line %d of \"%s\", the start symbol %s is a token",
230 lineno, input_file_name, s);
231 done(1);
232 }
233
234
235 void
restarted_warning(void)236 restarted_warning(void)
237 {
238 warnx("w - line %d of \"%s\", the start symbol has been redeclared",
239 lineno, input_file_name);
240 }
241
242
243 void
no_grammar(void)244 no_grammar(void)
245 {
246 warnx("e - line %d of \"%s\", no grammar has been specified",
247 lineno, input_file_name);
248 done(1);
249 }
250
251
252 void
terminal_lhs(int s_lineno)253 terminal_lhs(int s_lineno)
254 {
255 warnx("e - line %d of \"%s\", a token appears on the lhs of a production",
256 s_lineno, input_file_name);
257 done(1);
258 }
259
260
261 void
prec_redeclared(void)262 prec_redeclared(void)
263 {
264 warnx("w - line %d of \"%s\", conflicting %%prec specifiers",
265 lineno, input_file_name);
266 }
267
268
269 void
unterminated_action(int a_lineno,char * a_line,char * a_cptr)270 unterminated_action(int a_lineno, char *a_line, char *a_cptr)
271 {
272 warnx("e - line %d of \"%s\", unterminated action",
273 a_lineno, input_file_name);
274 print_pos(a_line, a_cptr);
275 done(1);
276 }
277
278
279 void
dollar_warning(int a_lineno,int i)280 dollar_warning(int a_lineno, int i)
281 {
282 warnx("w - line %d of \"%s\", $%d references beyond the \
283 end of the current rule", a_lineno, input_file_name, i);
284 }
285
286
287 void
dollar_error(int a_lineno,char * a_line,char * a_cptr)288 dollar_error(int a_lineno, char *a_line, char *a_cptr)
289 {
290 warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
291 print_pos(a_line, a_cptr);
292 done(1);
293 }
294
295
296 void
untyped_lhs(void)297 untyped_lhs(void)
298 {
299 warnx("e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
300 done(1);
301 }
302
303
304 void
untyped_rhs(int i,char * s)305 untyped_rhs(int i, char *s)
306 {
307 warnx("e - line %d of \"%s\", $%d (%s) is untyped",
308 lineno, input_file_name, i, s);
309 done(1);
310 }
311
312
313 void
unknown_rhs(int i)314 unknown_rhs(int i)
315 {
316 warnx("e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
317 done(1);
318 }
319
320
321 void
default_action_warning(void)322 default_action_warning(void)
323 {
324 warnx("w - line %d of \"%s\", the default action assigns an \
325 undefined value to $$", lineno, input_file_name);
326 }
327
328
329 void
undefined_goal(char * s)330 undefined_goal(char *s)
331 {
332 warnx("e - the start symbol %s is undefined", s);
333 done(1);
334 }
335
336
337 void
undefined_symbol_warning(char * s)338 undefined_symbol_warning(char *s)
339 {
340 warnx("w - the symbol %s is undefined", s);
341 }
342