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