1 /* $NetBSD: error.c,v 1.6 2010/12/25 23:43:30 christos Exp $ */ 2 /* Id: error.c,v 1.8 2010/11/24 15:10:20 tom Exp */ 3 4 #include "defs.h" 5 6 #include <sys/cdefs.h> 7 __RCSID("$NetBSD: error.c,v 1.6 2010/12/25 23:43:30 christos Exp $"); 8 9 /* routines for printing error messages */ 10 11 __dead void 12 fatal(const char *msg) 13 { 14 fprintf(stderr, "%s: f - %s\n", myname, msg); 15 done(2); 16 } 17 18 __dead void 19 no_space(void) 20 { 21 fprintf(stderr, "%s: f - out of space\n", myname); 22 done(2); 23 } 24 25 __dead void 26 open_error(const char *filename) 27 { 28 fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename); 29 done(2); 30 } 31 32 void 33 unexpected_EOF(void) 34 { 35 fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n", 36 myname, lineno, input_file_name); 37 done(1); 38 } 39 40 static void 41 print_pos(char *st_line, char *st_cptr) 42 { 43 char *s; 44 45 if (st_line == 0) 46 return; 47 for (s = st_line; *s != '\n'; ++s) 48 { 49 if (isprint(UCH(*s)) || *s == '\t') 50 putc(*s, stderr); 51 else 52 putc('?', stderr); 53 } 54 putc('\n', stderr); 55 for (s = st_line; s < st_cptr; ++s) 56 { 57 if (*s == '\t') 58 putc('\t', stderr); 59 else 60 putc(' ', stderr); 61 } 62 putc('^', stderr); 63 putc('\n', stderr); 64 } 65 66 __dead void 67 syntax_error(int st_lineno, char *st_line, char *st_cptr) 68 { 69 fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n", 70 myname, st_lineno, input_file_name); 71 print_pos(st_line, st_cptr); 72 done(1); 73 } 74 75 __dead void 76 unterminated_comment(int c_lineno, char *c_line, char *c_cptr) 77 { 78 fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n", 79 myname, c_lineno, input_file_name); 80 print_pos(c_line, c_cptr); 81 done(1); 82 } 83 84 __dead void 85 unterminated_string(int s_lineno, char *s_line, char *s_cptr) 86 { 87 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n", 88 myname, s_lineno, input_file_name); 89 print_pos(s_line, s_cptr); 90 done(1); 91 } 92 93 __dead void 94 unterminated_text(int t_lineno, char *t_line, char *t_cptr) 95 { 96 fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n", 97 myname, t_lineno, input_file_name); 98 print_pos(t_line, t_cptr); 99 done(1); 100 } 101 102 __dead void 103 unterminated_union(int u_lineno, char *u_line, char *u_cptr) 104 { 105 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \ 106 declaration\n", myname, u_lineno, input_file_name); 107 print_pos(u_line, u_cptr); 108 done(1); 109 } 110 111 __dead void 112 over_unionized(char *u_cptr) 113 { 114 fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \ 115 declarations\n", myname, lineno, input_file_name); 116 print_pos(line, u_cptr); 117 done(1); 118 } 119 120 __dead void 121 illegal_tag(int t_lineno, char *t_line, char *t_cptr) 122 { 123 fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n", 124 myname, t_lineno, input_file_name); 125 print_pos(t_line, t_cptr); 126 done(1); 127 } 128 129 __dead void 130 illegal_character(char *c_cptr) 131 { 132 fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n", 133 myname, lineno, input_file_name); 134 print_pos(line, c_cptr); 135 done(1); 136 } 137 138 __dead void 139 used_reserved(char *s) 140 { 141 fprintf(stderr, 142 "%s: e - line %d of \"%s\", illegal use of reserved symbol \ 143 %s\n", myname, lineno, input_file_name, s); 144 done(1); 145 } 146 147 __dead void 148 tokenized_start(char *s) 149 { 150 fprintf(stderr, 151 "%s: e - line %d of \"%s\", the start symbol %s cannot be \ 152 declared to be a token\n", myname, lineno, input_file_name, s); 153 done(1); 154 } 155 156 void 157 retyped_warning(char *s) 158 { 159 fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \ 160 redeclared\n", myname, lineno, input_file_name, s); 161 } 162 163 void 164 reprec_warning(char *s) 165 { 166 fprintf(stderr, 167 "%s: w - line %d of \"%s\", the precedence of %s has been \ 168 redeclared\n", myname, lineno, input_file_name, s); 169 } 170 171 void 172 revalued_warning(char *s) 173 { 174 fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \ 175 redeclared\n", myname, lineno, input_file_name, s); 176 } 177 178 void 179 terminal_start(char *s) 180 { 181 fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \ 182 token\n", myname, lineno, input_file_name, s); 183 done(1); 184 } 185 186 void 187 restarted_warning(void) 188 { 189 fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \ 190 redeclared\n", myname, lineno, input_file_name); 191 } 192 193 void 194 no_grammar(void) 195 { 196 fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \ 197 specified\n", myname, lineno, input_file_name); 198 done(1); 199 } 200 201 void 202 terminal_lhs(int s_lineno) 203 { 204 fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \ 205 of a production\n", myname, s_lineno, input_file_name); 206 done(1); 207 } 208 209 void 210 prec_redeclared(void) 211 { 212 fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \ 213 specifiers\n", myname, lineno, input_file_name); 214 } 215 216 void 217 unterminated_action(int a_lineno, char *a_line, char *a_cptr) 218 { 219 fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n", 220 myname, a_lineno, input_file_name); 221 print_pos(a_line, a_cptr); 222 done(1); 223 } 224 225 void 226 dollar_warning(int a_lineno, int i) 227 { 228 fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \ 229 end of the current rule\n", myname, a_lineno, input_file_name, i); 230 } 231 232 __dead void 233 dollar_error(int a_lineno, char *a_line, char *a_cptr) 234 { 235 fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n", 236 myname, a_lineno, input_file_name); 237 print_pos(a_line, a_cptr); 238 done(1); 239 } 240 241 __dead void 242 untyped_lhs(void) 243 { 244 fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n", 245 myname, lineno, input_file_name); 246 done(1); 247 } 248 249 __dead void 250 untyped_rhs(int i, char *s) 251 { 252 fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n", 253 myname, lineno, input_file_name, i, s); 254 done(1); 255 } 256 257 __dead void 258 unknown_rhs(int i) 259 { 260 fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n", 261 myname, lineno, input_file_name, i); 262 done(1); 263 } 264 265 void 266 default_action_warning(void) 267 { 268 fprintf(stderr, 269 "%s: w - line %d of \"%s\", the default action assigns an \ 270 undefined value to $$\n", myname, lineno, input_file_name); 271 } 272 273 void 274 undefined_goal(char *s) 275 { 276 fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s); 277 done(1); 278 } 279 280 void 281 undefined_symbol_warning(char *s) 282 { 283 fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s); 284 } 285