Move VarCreate() and VarDestroy() close to top of file, and add white
[dragonfly.git] / usr.bin / yacc / error.c
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  * 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.
23  *
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
34  * SUCH DAMAGE.
35  *
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 $
39  */
40
41 /* routines for printing error messages  */
42
43 #include <stdlib.h>
44 #include "defs.h"
45
46 static void print_pos(const char *, const char *);
47
48 void
49 fatal(const char *msg)
50 {
51     errx(2, "f - %s", msg);
52 }
53
54
55 void
56 no_space(void)
57 {
58     errx(2, "f - out of space");
59 }
60
61
62 void
63 open_error(const char *filename)
64 {
65     errx(2, "f - cannot open \"%s\"", filename);
66 }
67
68
69 void
70 unexpected_EOF(void)
71 {
72     errx(1, "e - line %d of \"%s\", unexpected end-of-file",
73             lineno, input_file_name);
74 }
75
76
77 static void
78 print_pos(const char *st_line, const char *st_cptr)
79 {
80     const char *s;
81
82     if (st_line == 0) return;
83     for (s = st_line; *s != '\n'; ++s)
84     {
85         if (isprint(*s) || *s == '\t')
86             putc(*s, stderr);
87         else
88             putc('?', stderr);
89     }
90     putc('\n', stderr);
91     for (s = st_line; s < st_cptr; ++s)
92     {
93         if (*s == '\t')
94             putc('\t', stderr);
95         else
96             putc(' ', stderr);
97     }
98     putc('^', stderr);
99     putc('\n', stderr);
100 }
101
102
103 void
104 syntax_error(int st_lineno, const char *st_line, const char *st_cptr)
105 {
106     warnx("e - line %d of \"%s\", syntax error",
107             st_lineno, input_file_name);
108     print_pos(st_line, st_cptr);
109     exit(1);
110 }
111
112
113 void
114 unterminated_comment(int c_lineno, const char *c_line, const char *c_cptr)
115 {
116     warnx("e - line %d of \"%s\", unmatched /*",
117             c_lineno, input_file_name);
118     print_pos(c_line, c_cptr);
119     exit(1);
120 }
121
122
123 void
124 unterminated_string(int s_lineno, const char *s_line, const char *s_cptr)
125 {
126     warnx("e - line %d of \"%s\", unterminated string",
127             s_lineno, input_file_name);
128     print_pos(s_line, s_cptr);
129     exit(1);
130 }
131
132
133 void
134 unterminated_text(int t_lineno, const char *t_line, const char *t_cptr)
135 {
136     warnx("e - line %d of \"%s\", unmatched %%{",
137             t_lineno, input_file_name);
138     print_pos(t_line, t_cptr);
139     exit(1);
140 }
141
142
143 void
144 unterminated_union(int u_lineno, const char *u_line, const char *u_cptr)
145 {
146     warnx("e - line %d of \"%s\", unterminated %%union declaration",
147                 u_lineno, input_file_name);
148     print_pos(u_line, u_cptr);
149     exit(1);
150 }
151
152
153 void
154 over_unionized(const char *u_cptr)
155 {
156     warnx("e - line %d of \"%s\", too many %%union declarations",
157                 lineno, input_file_name);
158     print_pos(line, u_cptr);
159     exit(1);
160 }
161
162
163 void
164 illegal_tag(int t_lineno, const char *t_line, const char *t_cptr)
165 {
166     warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
167     print_pos(t_line, t_cptr);
168     exit(1);
169 }
170
171
172 void
173 illegal_character(const char *c_cptr)
174 {
175     warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
176     print_pos(line, c_cptr);
177     exit(1);
178 }
179
180
181 void
182 used_reserved(const char *s)
183 {
184     errx(1, "e - line %d of \"%s\", illegal use of reserved symbol %s",
185                 lineno, input_file_name, s);
186 }
187
188
189 void
190 tokenized_start(const char *s)
191 {
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);
194 }
195
196
197 void
198 retyped_warning(const char *s)
199 {
200     warnx("w - line %d of \"%s\", the type of %s has been redeclared",
201                 lineno, input_file_name, s);
202 }
203
204
205 void
206 reprec_warning(const char *s)
207 {
208     warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
209                 lineno, input_file_name, s);
210 }
211
212
213 void
214 revalued_warning(const char *s)
215 {
216     warnx("w - line %d of \"%s\", the value of %s has been redeclared",
217                 lineno, input_file_name, s);
218 }
219
220
221 void
222 terminal_start(const char *s)
223 {
224     errx(1, "e - line %d of \"%s\", the start symbol %s is a token",
225                 lineno, input_file_name, s);
226 }
227
228
229 void
230 restarted_warning(void)
231 {
232     warnx("w - line %d of \"%s\", the start symbol has been redeclared",
233                 lineno, input_file_name);
234 }
235
236
237 void
238 no_grammar(void)
239 {
240     errx(1, "e - line %d of \"%s\", no grammar has been specified",
241                 lineno, input_file_name);
242 }
243
244
245 void
246 terminal_lhs(int s_lineno)
247 {
248     errx(1, "e - line %d of \"%s\", a token appears on the lhs of a production",
249                 s_lineno, input_file_name);
250 }
251
252
253 void
254 prec_redeclared(void)
255 {
256     warnx("w - line %d of  \"%s\", conflicting %%prec specifiers",
257                 lineno, input_file_name);
258 }
259
260
261 void
262 unterminated_action(int a_lineno, const char *a_line, const char *a_cptr)
263 {
264     warnx("e - line %d of \"%s\", unterminated action",
265             a_lineno, input_file_name);
266     print_pos(a_line, a_cptr);
267 }
268
269
270 void
271 dollar_warning(int a_lineno, int i)
272 {
273     warnx("w - line %d of \"%s\", $%d references beyond the \
274 end of the current rule", a_lineno, input_file_name, i);
275 }
276
277
278 void
279 dollar_error(int a_lineno, const char *a_line, const char *a_cptr)
280 {
281     warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
282     print_pos(a_line, a_cptr);
283     exit(1);
284 }
285
286
287 void
288 untyped_lhs(void)
289 {
290     errx(1, "e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
291 }
292
293
294 void
295 untyped_rhs(int i, const char *s)
296 {
297     errx(1, "e - line %d of \"%s\", $%d (%s) is untyped",
298             lineno, input_file_name, i, s);
299 }
300
301
302 void
303 unknown_rhs(int i)
304 {
305     errx(1, "e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
306 }
307
308
309 void
310 default_action_warning(void)
311 {
312     warnx("w - line %d of \"%s\", the default action assigns an \
313 undefined value to $$", lineno, input_file_name);
314 }
315
316
317 void
318 undefined_goal(const char *s)
319 {
320     errx(1, "e - the start symbol %s is undefined", s);
321 }
322
323
324 void
325 undefined_symbol_warning(const char *s)
326 {
327     warnx("w - the symbol %s is undefined", s);
328 }