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