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