386BSD 0.1 development
[unix-history] / usr / src / usr.bin / yacc / error.c
CommitLineData
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
38static 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
46fatal(msg)
47char *msg;
48{
49 fprintf(stderr, "%s: f - %s\n", myname, msg);
50 done(2);
51}
52
53
54no_space()
55{
56 fprintf(stderr, "%s: f - out of space\n", myname);
57 done(2);
58}
59
60
61open_error(filename)
62char *filename;
63{
64 fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
65 done(2);
66}
67
68
69unexpected_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
77print_pos(st_line, st_cptr)
78char *st_line;
79char *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
104syntax_error(st_lineno, st_line, st_cptr)
105int st_lineno;
106char *st_line;
107char *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
116unterminated_comment(c_lineno, c_line, c_cptr)
117int c_lineno;
118char *c_line;
119char *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
128unterminated_string(s_lineno, s_line, s_cptr)
129int s_lineno;
130char *s_line;
131char *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
140unterminated_text(t_lineno, t_line, t_cptr)
141int t_lineno;
142char *t_line;
143char *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
152unterminated_union(u_lineno, u_line, u_cptr)
153int u_lineno;
154char *u_line;
155char *u_cptr;
156{
157 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
158declaration\n", myname, u_lineno, input_file_name);
159 print_pos(u_line, u_cptr);
160 done(1);
161}
162
163
164over_unionized(u_cptr)
165char *u_cptr;
166{
167 fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
168declarations\n", myname, lineno, input_file_name);
169 print_pos(line, u_cptr);
170 done(1);
171}
172
173
174illegal_tag(t_lineno, t_line, t_cptr)
175int t_lineno;
176char *t_line;
177char *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
186illegal_character(c_cptr)
187char *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
196used_reserved(s)
197char *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
205tokenized_start(s)
206char *s;
207{
208 fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
209declared to be a token\n", myname, lineno, input_file_name, s);
210 done(1);
211}
212
213
214retyped_warning(s)
215char *s;
216{
217 fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
218redeclared\n", myname, lineno, input_file_name, s);
219}
220
221
222reprec_warning(s)
223char *s;
224{
225 fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
226redeclared\n", myname, lineno, input_file_name, s);
227}
228
229
230revalued_warning(s)
231char *s;
232{
233 fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
234redeclared\n", myname, lineno, input_file_name, s);
235}
236
237
238terminal_start(s)
239char *s;
240{
241 fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
242token\n", myname, lineno, input_file_name, s);
243 done(1);
244}
245
246
247restarted_warning()
248{
249 fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
250redeclared\n", myname, lineno, input_file_name);
251}
252
253
254no_grammar()
255{
256 fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
257specified\n", myname, lineno, input_file_name);
258 done(1);
259}
260
261
262terminal_lhs(s_lineno)
263int s_lineno;
264{
265 fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
266of a production\n", myname, s_lineno, input_file_name);
267 done(1);
268}
269
270
271prec_redeclared()
272{
273 fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \
274specifiers\n", myname, lineno, input_file_name);
275}
276
277
278unterminated_action(a_lineno, a_line, a_cptr)
279int a_lineno;
280char *a_line;
281char *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
290dollar_warning(a_lineno, i)
291int a_lineno;
292int i;
293{
294 fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
295end of the current rule\n", myname, a_lineno, input_file_name, i);
296}
297
298
299dollar_error(a_lineno, a_line, a_cptr)
300int a_lineno;
301char *a_line;
302char *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
311untyped_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
319untyped_rhs(i, s)
320int i;
321char *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
329unknown_rhs(i)
330int 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
338default_action_warning()
339{
340 fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
341undefined value to $$\n", myname, lineno, input_file_name);
342}
343
344
345undefined_goal(s)
346char *s;
347{
348 fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
349 done(1);
350}
351
352
353undefined_symbol_warning(s)
354char *s;
355{
356 fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
357}