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