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