1 /* $NetBSD: error.c,v 1.2 2009/10/29 00:56:19 christos Exp $ */
2 /* Id: error.c,v 1.6 2008/11/24 21:30:35 tom Exp */
7 __RCSID("$NetBSD: error.c,v 1.2 2009/10/29 00:56:19 christos Exp $");
10 /* routines for printing error messages */
13 fatal(const char *msg
)
15 fprintf(stderr
, "%s: f - %s\n", myname
, msg
);
22 fprintf(stderr
, "%s: f - out of space\n", myname
);
27 open_error(const char *filename
)
29 fprintf(stderr
, "%s: f - cannot open \"%s\"\n", myname
, filename
);
36 fprintf(stderr
, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
37 myname
, lineno
, input_file_name
);
42 print_pos(char *st_line
, char *st_cptr
)
48 for (s
= st_line
; *s
!= '\n'; ++s
)
50 if (isprint((unsigned char)*s
) || *s
== '\t')
56 for (s
= st_line
; s
< st_cptr
; ++s
)
68 syntax_error(int st_lineno
, char *st_line
, char *st_cptr
)
70 fprintf(stderr
, "%s: e - line %d of \"%s\", syntax error\n",
71 myname
, st_lineno
, input_file_name
);
72 print_pos(st_line
, st_cptr
);
77 unterminated_comment(int c_lineno
, char *c_line
, char *c_cptr
)
79 fprintf(stderr
, "%s: e - line %d of \"%s\", unmatched /*\n",
80 myname
, c_lineno
, input_file_name
);
81 print_pos(c_line
, c_cptr
);
86 unterminated_string(int s_lineno
, char *s_line
, char *s_cptr
)
88 fprintf(stderr
, "%s: e - line %d of \"%s\", unterminated string\n",
89 myname
, s_lineno
, input_file_name
);
90 print_pos(s_line
, s_cptr
);
95 unterminated_text(int t_lineno
, char *t_line
, char *t_cptr
)
97 fprintf(stderr
, "%s: e - line %d of \"%s\", unmatched %%{\n",
98 myname
, t_lineno
, input_file_name
);
99 print_pos(t_line
, t_cptr
);
104 unterminated_union(int u_lineno
, char *u_line
, char *u_cptr
)
106 fprintf(stderr
, "%s: e - line %d of \"%s\", unterminated %%union \
107 declaration\n", myname
, u_lineno
, input_file_name
);
108 print_pos(u_line
, u_cptr
);
113 over_unionized(char *u_cptr
)
115 fprintf(stderr
, "%s: e - line %d of \"%s\", too many %%union \
116 declarations\n", myname
, lineno
, input_file_name
);
117 print_pos(line
, u_cptr
);
122 illegal_tag(int t_lineno
, char *t_line
, char *t_cptr
)
124 fprintf(stderr
, "%s: e - line %d of \"%s\", illegal tag\n",
125 myname
, t_lineno
, input_file_name
);
126 print_pos(t_line
, t_cptr
);
131 illegal_character(char *c_cptr
)
133 fprintf(stderr
, "%s: e - line %d of \"%s\", illegal character\n",
134 myname
, lineno
, input_file_name
);
135 print_pos(line
, c_cptr
);
140 used_reserved(char *s
)
143 "%s: e - line %d of \"%s\", illegal use of reserved symbol \
144 %s\n", myname
, lineno
, input_file_name
, s
);
149 tokenized_start(char *s
)
152 "%s: e - line %d of \"%s\", the start symbol %s cannot be \
153 declared to be a token\n", myname
, lineno
, input_file_name
, s
);
158 retyped_warning(char *s
)
160 fprintf(stderr
, "%s: w - line %d of \"%s\", the type of %s has been \
161 redeclared\n", myname
, lineno
, input_file_name
, s
);
165 reprec_warning(char *s
)
168 "%s: w - line %d of \"%s\", the precedence of %s has been \
169 redeclared\n", myname
, lineno
, input_file_name
, s
);
173 revalued_warning(char *s
)
175 fprintf(stderr
, "%s: w - line %d of \"%s\", the value of %s has been \
176 redeclared\n", myname
, lineno
, input_file_name
, s
);
180 terminal_start(char *s
)
182 fprintf(stderr
, "%s: e - line %d of \"%s\", the start symbol %s is a \
183 token\n", myname
, lineno
, input_file_name
, s
);
188 restarted_warning(void)
190 fprintf(stderr
, "%s: w - line %d of \"%s\", the start symbol has been \
191 redeclared\n", myname
, lineno
, input_file_name
);
197 fprintf(stderr
, "%s: e - line %d of \"%s\", no grammar has been \
198 specified\n", myname
, lineno
, input_file_name
);
203 terminal_lhs(int s_lineno
)
205 fprintf(stderr
, "%s: e - line %d of \"%s\", a token appears on the lhs \
206 of a production\n", myname
, s_lineno
, input_file_name
);
211 prec_redeclared(void)
213 fprintf(stderr
, "%s: w - line %d of \"%s\", conflicting %%prec \
214 specifiers\n", myname
, lineno
, input_file_name
);
218 unterminated_action(int a_lineno
, char *a_line
, char *a_cptr
)
220 fprintf(stderr
, "%s: e - line %d of \"%s\", unterminated action\n",
221 myname
, a_lineno
, input_file_name
);
222 print_pos(a_line
, a_cptr
);
227 dollar_warning(int a_lineno
, int i
)
229 fprintf(stderr
, "%s: w - line %d of \"%s\", $%d references beyond the \
230 end of the current rule\n", myname
, a_lineno
, input_file_name
, i
);
234 dollar_error(int a_lineno
, char *a_line
, char *a_cptr
)
236 fprintf(stderr
, "%s: e - line %d of \"%s\", illegal $-name\n",
237 myname
, a_lineno
, input_file_name
);
238 print_pos(a_line
, a_cptr
);
245 fprintf(stderr
, "%s: e - line %d of \"%s\", $$ is untyped\n",
246 myname
, lineno
, input_file_name
);
251 untyped_rhs(int i
, char *s
)
253 fprintf(stderr
, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
254 myname
, lineno
, input_file_name
, i
, s
);
261 fprintf(stderr
, "%s: e - line %d of \"%s\", $%d is untyped\n",
262 myname
, lineno
, input_file_name
, i
);
267 default_action_warning(void)
270 "%s: w - line %d of \"%s\", the default action assigns an \
271 undefined value to $$\n", myname
, lineno
, input_file_name
);
275 undefined_goal(char *s
)
277 fprintf(stderr
, "%s: e - the start symbol %s is undefined\n", myname
, s
);
282 undefined_symbol_warning(char *s
)
284 fprintf(stderr
, "%s: w - the symbol %s is undefined\n", myname
, s
);