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