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