1/* $Id: error.c,v 1.11 2014/04/07 22:22:49 tom Exp $ */
2
3/* routines for printing error messages  */
4
5#include "defs.h"
6
7void
8fatal(const char *msg)
9{
10    fprintf(stderr, "%s: f - %s\n", myname, msg);
11    done(2);
12}
13
14void
15no_space(void)
16{
17    fprintf(stderr, "%s: f - out of space\n", myname);
18    done(2);
19}
20
21void
22open_error(const char *filename)
23{
24    fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
25    done(2);
26}
27
28void
29missing_brace(void)
30{
31    fprintf(stderr, "%s: e - line %d of \"%s\", missing '}'\n",
32	    myname, lineno, input_file_name);
33    done(1);
34}
35
36void
37unexpected_EOF(void)
38{
39    fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
40	    myname, lineno, input_file_name);
41    done(1);
42}
43
44static void
45print_pos(const char *st_line, const char *st_cptr)
46{
47    const char *s;
48
49    if (st_line == 0)
50	return;
51    for (s = st_line; *s != '\n'; ++s)
52    {
53	if (isprint(UCH(*s)) || *s == '\t')
54	    putc(*s, stderr);
55	else
56	    putc('?', stderr);
57    }
58    putc('\n', stderr);
59    for (s = st_line; s < st_cptr; ++s)
60    {
61	if (*s == '\t')
62	    putc('\t', stderr);
63	else
64	    putc(' ', stderr);
65    }
66    putc('^', stderr);
67    putc('\n', stderr);
68}
69
70void
71syntax_error(int st_lineno, char *st_line, char *st_cptr)
72{
73    fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
74	    myname, st_lineno, input_file_name);
75    print_pos(st_line, st_cptr);
76    done(1);
77}
78
79void
80unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
81{
82    fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
83	    myname, c_lineno, input_file_name);
84    print_pos(c_line, c_cptr);
85    done(1);
86}
87
88void
89unterminated_string(int s_lineno, char *s_line, char *s_cptr)
90{
91    fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
92	    myname, s_lineno, input_file_name);
93    print_pos(s_line, s_cptr);
94    done(1);
95}
96
97void
98unterminated_text(int t_lineno, char *t_line, char *t_cptr)
99{
100    fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
101	    myname, t_lineno, input_file_name);
102    print_pos(t_line, t_cptr);
103    done(1);
104}
105
106void
107unterminated_union(int u_lineno, char *u_line, char *u_cptr)
108{
109    fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
110declaration\n", myname, u_lineno, input_file_name);
111    print_pos(u_line, u_cptr);
112    done(1);
113}
114
115void
116over_unionized(char *u_cptr)
117{
118    fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
119declarations\n", myname, lineno, input_file_name);
120    print_pos(line, u_cptr);
121    done(1);
122}
123
124void
125illegal_tag(int t_lineno, char *t_line, char *t_cptr)
126{
127    fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
128	    myname, t_lineno, input_file_name);
129    print_pos(t_line, t_cptr);
130    done(1);
131}
132
133void
134illegal_character(char *c_cptr)
135{
136    fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
137	    myname, lineno, input_file_name);
138    print_pos(line, c_cptr);
139    done(1);
140}
141
142void
143used_reserved(char *s)
144{
145    fprintf(stderr,
146	    "%s: e - line %d of \"%s\", illegal use of reserved symbol \
147%s\n", myname, lineno, input_file_name, s);
148    done(1);
149}
150
151void
152tokenized_start(char *s)
153{
154    fprintf(stderr,
155	    "%s: e - line %d of \"%s\", the start symbol %s cannot be \
156declared to be a token\n", myname, lineno, input_file_name, s);
157    done(1);
158}
159
160void
161retyped_warning(char *s)
162{
163    fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
164redeclared\n", myname, lineno, input_file_name, s);
165}
166
167void
168reprec_warning(char *s)
169{
170    fprintf(stderr,
171	    "%s: w - line %d of \"%s\", the precedence of %s has been \
172redeclared\n", myname, lineno, input_file_name, s);
173}
174
175void
176revalued_warning(char *s)
177{
178    fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
179redeclared\n", myname, lineno, input_file_name, s);
180}
181
182void
183terminal_start(char *s)
184{
185    fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
186token\n", myname, lineno, input_file_name, s);
187    done(1);
188}
189
190void
191restarted_warning(void)
192{
193    fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
194redeclared\n", myname, lineno, input_file_name);
195}
196
197void
198no_grammar(void)
199{
200    fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
201specified\n", myname, lineno, input_file_name);
202    done(1);
203}
204
205void
206terminal_lhs(int s_lineno)
207{
208    fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
209of a production\n", myname, s_lineno, input_file_name);
210    done(1);
211}
212
213void
214prec_redeclared(void)
215{
216    fprintf(stderr, "%s: w - line %d of  \"%s\", conflicting %%prec \
217specifiers\n", myname, lineno, input_file_name);
218}
219
220void
221unterminated_action(int a_lineno, char *a_line, char *a_cptr)
222{
223    fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
224	    myname, a_lineno, input_file_name);
225    print_pos(a_line, a_cptr);
226    done(1);
227}
228
229void
230dollar_warning(int a_lineno, int i)
231{
232    fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
233end of the current rule\n", myname, a_lineno, input_file_name, i);
234}
235
236void
237dollar_error(int a_lineno, char *a_line, char *a_cptr)
238{
239    fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
240	    myname, a_lineno, input_file_name);
241    print_pos(a_line, a_cptr);
242    done(1);
243}
244
245void
246untyped_lhs(void)
247{
248    fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
249	    myname, lineno, input_file_name);
250    done(1);
251}
252
253void
254untyped_rhs(int i, char *s)
255{
256    fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
257	    myname, lineno, input_file_name, i, s);
258    done(1);
259}
260
261void
262unknown_rhs(int i)
263{
264    fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
265	    myname, lineno, input_file_name, i);
266    done(1);
267}
268
269void
270default_action_warning(void)
271{
272    fprintf(stderr,
273	    "%s: w - line %d of \"%s\", the default action assigns an \
274undefined value to $$\n", myname, lineno, input_file_name);
275}
276
277void
278undefined_goal(char *s)
279{
280    fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
281    done(1);
282}
283
284void
285undefined_symbol_warning(char *s)
286{
287    fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
288}
289
290#if ! defined(YYBTYACC)
291void
292unsupported_flag_warning(const char *flag, const char *details)
293{
294    fprintf(stderr, "%s: w - %s flag unsupported, %s\n",
295	    myname, flag, details);
296}
297#endif
298
299#if defined(YYBTYACC)
300void
301at_warning(int a_lineno, int i)
302{
303    fprintf(stderr, "%s: w - line %d of \"%s\", @%d references beyond the \
304end of the current rule\n", myname, a_lineno, input_file_name, i);
305}
306
307void
308at_error(int a_lineno, char *a_line, char *a_cptr)
309{
310    fprintf(stderr,
311	    "%s: e - line %d of \"%s\", illegal @$ or @N reference\n",
312	    myname, a_lineno, input_file_name);
313    print_pos(a_line, a_cptr);
314    done(1);
315}
316
317void
318unterminated_arglist(int a_lineno, char *a_line, char *a_cptr)
319{
320    fprintf(stderr,
321	    "%s: e - line %d of \"%s\", unterminated argument list\n",
322	    myname, a_lineno, input_file_name);
323    print_pos(a_line, a_cptr);
324    done(1);
325}
326
327void
328arg_number_disagree_warning(int a_lineno, char *a_name)
329{
330    fprintf(stderr, "%s: w - line %d of \"%s\", number of arguments of %s "
331	    "doesn't agree with previous declaration\n",
332	    myname, a_lineno, input_file_name, a_name);
333}
334
335void
336bad_formals(void)
337{
338    fprintf(stderr, "%s: e - line %d of \"%s\", bad formal argument list\n",
339	    myname, lineno, input_file_name);
340    print_pos(line, cptr);
341    done(1);
342}
343
344void
345arg_type_disagree_warning(int a_lineno, int i, char *a_name)
346{
347    fprintf(stderr, "%s: w - line %d of \"%s\", type of argument %d "
348	    "to %s doesn't agree with previous declaration\n",
349	    myname, a_lineno, input_file_name, i, a_name);
350}
351
352void
353unknown_arg_warning(int d_lineno, const char *dlr_opt, const char *d_arg, const char
354		    *d_line, const char *d_cptr)
355{
356    fprintf(stderr, "%s: w - line %d of \"%s\", unknown argument %s%s\n",
357	    myname, d_lineno, input_file_name, dlr_opt, d_arg);
358    print_pos(d_line, d_cptr);
359}
360
361void
362untyped_arg_warning(int a_lineno, const char *dlr_opt, const char *a_name)
363{
364    fprintf(stderr, "%s: w - line %d of \"%s\", untyped argument %s%s\n",
365	    myname, a_lineno, input_file_name, dlr_opt, a_name);
366}
367
368void
369wrong_number_args_warning(const char *which, const char *a_name)
370{
371    fprintf(stderr,
372	    "%s: w - line %d of \"%s\", wrong number of %sarguments for %s\n",
373	    myname, lineno, input_file_name, which, a_name);
374    print_pos(line, cptr);
375}
376
377void
378wrong_type_for_arg_warning(int i, char *a_name)
379{
380    fprintf(stderr,
381	    "%s: w - line %d of \"%s\", wrong type for default argument %d to %s\n",
382	    myname, lineno, input_file_name, i, a_name);
383    print_pos(line, cptr);
384}
385
386void
387start_requires_args(char *a_name)
388{
389    fprintf(stderr,
390	    "%s: w - line %d of \"%s\", start symbol %s requires arguments\n",
391	    myname, 0, input_file_name, a_name);
392
393}
394
395void
396destructor_redeclared_warning(int a_lineno, char *a_line, char *a_cptr)
397{
398    fprintf(stderr, "%s: w - line %d of \"%s\", destructor redeclared\n",
399	    myname, a_lineno, input_file_name);
400    print_pos(a_line, a_cptr);
401}
402#endif
403