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