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