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