1 /***********************************************************************/
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the Q Public License version 1.0. */
11 /***********************************************************************/
13 /* Based on public-domain code from Berkeley Yacc */
15 /* $Id: error.c 6654 2004-11-02 10:48:14Z doligez $ */
17 /* routines for printing error messages */
23 fprintf(stderr, "%s: f - %s\n", myname, msg);
30 fprintf(stderr, "%s: f - out of space\n", myname);
35 void open_error(char *filename)
37 fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
42 void unexpected_EOF(void)
44 fprintf(stderr, "File \"%s\", line %d: unexpected end-of-file\n",
45 virtual_input_file_name, lineno);
50 void print_pos(char *st_line, char *st_cptr)
54 if (st_line == 0) return;
55 for (s = st_line; *s != '\n'; ++s)
57 if (isprint((unsigned char) *s) || *s == '\t')
63 for (s = st_line; s < st_cptr; ++s)
75 void syntax_error(int st_lineno, char *st_line, char *st_cptr)
77 fprintf(stderr, "File \"%s\", line %d: syntax error\n",
78 virtual_input_file_name, st_lineno);
79 print_pos(st_line, st_cptr);
84 void unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
86 fprintf(stderr, "File \"%s\", line %d: unmatched /*\n",
87 virtual_input_file_name, c_lineno);
88 print_pos(c_line, c_cptr);
93 void unterminated_string(int s_lineno, char *s_line, char *s_cptr)
95 fprintf(stderr, "File \"%s\", line %d: unterminated string\n",
96 virtual_input_file_name, s_lineno);
97 print_pos(s_line, s_cptr);
102 void unterminated_text(int t_lineno, char *t_line, char *t_cptr)
104 fprintf(stderr, "File \"%s\", line %d: unmatched %%{\n",
105 virtual_input_file_name, t_lineno);
106 print_pos(t_line, t_cptr);
111 void unterminated_union(int u_lineno, char *u_line, char *u_cptr)
113 fprintf(stderr, "File \"%s\", line %d: unterminated %%union declaration\n",
114 virtual_input_file_name, u_lineno);
115 print_pos(u_line, u_cptr);
120 void over_unionized(char *u_cptr)
122 fprintf(stderr, "File \"%s\", line %d: too many %%union declarations\n",
123 virtual_input_file_name, lineno);
124 print_pos(line, u_cptr);
129 void illegal_tag(int t_lineno, char *t_line, char *t_cptr)
131 fprintf(stderr, "File \"%s\", line %d: illegal tag\n",
132 virtual_input_file_name, t_lineno);
133 print_pos(t_line, t_cptr);
138 void illegal_character(char *c_cptr)
140 fprintf(stderr, "File \"%s\", line %d: illegal character\n",
141 virtual_input_file_name, lineno);
142 print_pos(line, c_cptr);
147 void used_reserved(char *s)
149 fprintf(stderr, "File \"%s\", line %d: illegal use of reserved symbol \
150 `%s'\n", virtual_input_file_name, lineno, s);
155 void tokenized_start(char *s)
157 fprintf(stderr, "File \"%s\", line %d: the start symbol `%s' cannot \
158 be declared to be a token\n", virtual_input_file_name, lineno, s);
163 void retyped_warning(char *s)
165 fprintf(stderr, "File \"%s\", line %d: warning: the type of `%s' has been \
166 redeclared\n", virtual_input_file_name, lineno, s);
170 void reprec_warning(char *s)
172 fprintf(stderr, "File \"%s\", line %d: warning: the precedence of `%s' has \
173 been redeclared\n", virtual_input_file_name, lineno, s);
177 void revalued_warning(char *s)
179 fprintf(stderr, "File \"%s\", line %d: warning: the value of `%s' has been \
180 redeclared\n", virtual_input_file_name, lineno, s);
184 void terminal_start(char *s)
186 fprintf(stderr, "File \"%s\", line %d: the entry point `%s' is a \
187 token\n", virtual_input_file_name, lineno, s);
191 void too_many_entries(void)
193 fprintf(stderr, "File \"%s\", line %d: more than 256 entry points\n",
194 virtual_input_file_name, lineno);
199 void no_grammar(void)
201 fprintf(stderr, "File \"%s\", line %d: no grammar has been specified\n",
202 virtual_input_file_name, lineno);
207 void terminal_lhs(int s_lineno)
209 fprintf(stderr, "File \"%s\", line %d: a token appears on the lhs \
210 of a production\n", virtual_input_file_name, s_lineno);
215 void prec_redeclared(void)
217 fprintf(stderr, "File \"%s\", line %d: warning: conflicting %%prec \
218 specifiers\n", virtual_input_file_name, lineno);
222 void unterminated_action(int a_lineno, char *a_line, char *a_cptr)
224 fprintf(stderr, "File \"%s\", line %d: unterminated action\n",
225 virtual_input_file_name, a_lineno);
226 print_pos(a_line, a_cptr);
231 void dollar_warning(int a_lineno, int i)
233 fprintf(stderr, "File \"%s\", line %d: warning: $%d references beyond the \
234 end of the current rule\n", virtual_input_file_name, a_lineno, i);
238 void dollar_error(int a_lineno, char *a_line, char *a_cptr)
240 fprintf(stderr, "File \"%s\", line %d: illegal $-name\n",
241 virtual_input_file_name, a_lineno);
242 print_pos(a_line, a_cptr);
247 void untyped_lhs(void)
249 fprintf(stderr, "File \"%s\", line %d: $$ is untyped\n",
250 virtual_input_file_name, lineno);
255 void untyped_rhs(int i, char *s)
257 fprintf(stderr, "File \"%s\", line %d: $%d (%s) is untyped\n",
258 virtual_input_file_name, lineno, i, s);
263 void unknown_rhs(int i)
265 fprintf(stderr, "File \"%s\", line %d: $%d is unbound\n",
266 virtual_input_file_name, lineno, i);
270 void illegal_token_ref(int i, char *name)
272 fprintf(stderr, "File \"%s\", line %d: $%d refers to terminal `%s', \
273 which has no argument\n",
274 virtual_input_file_name, lineno, i, name);
278 void default_action_error(void)
280 fprintf(stderr, "File \"%s\", line %d: no action specified for this \
282 virtual_input_file_name, lineno);
287 void undefined_goal(char *s)
289 fprintf(stderr, "%s: e - the start symbol `%s' is undefined\n", myname, s);
293 void undefined_symbol(char *s)
295 fprintf(stderr, "%s: e - the symbol `%s' is undefined\n", myname, s);
300 void entry_without_type(char *s)
303 "%s: e - no type has been declared for the start symbol `%s'\n",
308 void polymorphic_entry_point(char *s)
311 "%s: e - the start symbol `%s' has a polymorphic type\n",