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