updated with Tizen:Base source codes
[external/byacc.git] / error.c
1 /* $Id: error.c,v 1.6 2008/11/24 21:30:35 tom Exp $ */
2
3 /* routines for printing error messages  */
4
5 #include "defs.h"
6
7 void
8 fatal(const char *msg)
9 {
10     fprintf(stderr, "%s: f - %s\n", myname, msg);
11     done(2);
12 }
13
14 void
15 no_space(void)
16 {
17     fprintf(stderr, "%s: f - out of space\n", myname);
18     done(2);
19 }
20
21 void
22 open_error(const char *filename)
23 {
24     fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
25     done(2);
26 }
27
28 void
29 unexpected_EOF(void)
30 {
31     fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
32             myname, lineno, input_file_name);
33     done(1);
34 }
35
36 void
37 print_pos(char *st_line, char *st_cptr)
38 {
39     char *s;
40
41     if (st_line == 0)
42         return;
43     for (s = st_line; *s != '\n'; ++s)
44     {
45         if (isprint(*s) || *s == '\t')
46             putc(*s, stderr);
47         else
48             putc('?', stderr);
49     }
50     putc('\n', stderr);
51     for (s = st_line; s < st_cptr; ++s)
52     {
53         if (*s == '\t')
54             putc('\t', stderr);
55         else
56             putc(' ', stderr);
57     }
58     putc('^', stderr);
59     putc('\n', stderr);
60 }
61
62 void
63 syntax_error(int st_lineno, char *st_line, char *st_cptr)
64 {
65     fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
66             myname, st_lineno, input_file_name);
67     print_pos(st_line, st_cptr);
68     done(1);
69 }
70
71 void
72 unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
73 {
74     fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
75             myname, c_lineno, input_file_name);
76     print_pos(c_line, c_cptr);
77     done(1);
78 }
79
80 void
81 unterminated_string(int s_lineno, char *s_line, char *s_cptr)
82 {
83     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
84             myname, s_lineno, input_file_name);
85     print_pos(s_line, s_cptr);
86     done(1);
87 }
88
89 void
90 unterminated_text(int t_lineno, char *t_line, char *t_cptr)
91 {
92     fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
93             myname, t_lineno, input_file_name);
94     print_pos(t_line, t_cptr);
95     done(1);
96 }
97
98 void
99 unterminated_union(int u_lineno, char *u_line, char *u_cptr)
100 {
101     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
102 declaration\n", myname, u_lineno, input_file_name);
103     print_pos(u_line, u_cptr);
104     done(1);
105 }
106
107 void
108 over_unionized(char *u_cptr)
109 {
110     fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
111 declarations\n", myname, lineno, input_file_name);
112     print_pos(line, u_cptr);
113     done(1);
114 }
115
116 void
117 illegal_tag(int t_lineno, char *t_line, char *t_cptr)
118 {
119     fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
120             myname, t_lineno, input_file_name);
121     print_pos(t_line, t_cptr);
122     done(1);
123 }
124
125 void
126 illegal_character(char *c_cptr)
127 {
128     fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
129             myname, lineno, input_file_name);
130     print_pos(line, c_cptr);
131     done(1);
132 }
133
134 void
135 used_reserved(char *s)
136 {
137     fprintf(stderr,
138             "%s: e - line %d of \"%s\", illegal use of reserved symbol \
139 %s\n", myname, lineno, input_file_name, s);
140     done(1);
141 }
142
143 void
144 tokenized_start(char *s)
145 {
146     fprintf(stderr,
147             "%s: e - line %d of \"%s\", the start symbol %s cannot be \
148 declared to be a token\n", myname, lineno, input_file_name, s);
149     done(1);
150 }
151
152 void
153 retyped_warning(char *s)
154 {
155     fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
156 redeclared\n", myname, lineno, input_file_name, s);
157 }
158
159 void
160 reprec_warning(char *s)
161 {
162     fprintf(stderr,
163             "%s: w - line %d of \"%s\", the precedence of %s has been \
164 redeclared\n", myname, lineno, input_file_name, s);
165 }
166
167 void
168 revalued_warning(char *s)
169 {
170     fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
171 redeclared\n", myname, lineno, input_file_name, s);
172 }
173
174 void
175 terminal_start(char *s)
176 {
177     fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
178 token\n", myname, lineno, input_file_name, s);
179     done(1);
180 }
181
182 void
183 restarted_warning(void)
184 {
185     fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
186 redeclared\n", myname, lineno, input_file_name);
187 }
188
189 void
190 no_grammar(void)
191 {
192     fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
193 specified\n", myname, lineno, input_file_name);
194     done(1);
195 }
196
197 void
198 terminal_lhs(int s_lineno)
199 {
200     fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
201 of a production\n", myname, s_lineno, input_file_name);
202     done(1);
203 }
204
205 void
206 prec_redeclared(void)
207 {
208     fprintf(stderr, "%s: w - line %d of  \"%s\", conflicting %%prec \
209 specifiers\n", myname, lineno, input_file_name);
210 }
211
212 void
213 unterminated_action(int a_lineno, char *a_line, char *a_cptr)
214 {
215     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
216             myname, a_lineno, input_file_name);
217     print_pos(a_line, a_cptr);
218     done(1);
219 }
220
221 void
222 dollar_warning(int a_lineno, int i)
223 {
224     fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
225 end of the current rule\n", myname, a_lineno, input_file_name, i);
226 }
227
228 void
229 dollar_error(int a_lineno, char *a_line, char *a_cptr)
230 {
231     fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
232             myname, a_lineno, input_file_name);
233     print_pos(a_line, a_cptr);
234     done(1);
235 }
236
237 void
238 untyped_lhs(void)
239 {
240     fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
241             myname, lineno, input_file_name);
242     done(1);
243 }
244
245 void
246 untyped_rhs(int i, char *s)
247 {
248     fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
249             myname, lineno, input_file_name, i, s);
250     done(1);
251 }
252
253 void
254 unknown_rhs(int i)
255 {
256     fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
257             myname, lineno, input_file_name, i);
258     done(1);
259 }
260
261 void
262 default_action_warning(void)
263 {
264     fprintf(stderr,
265             "%s: w - line %d of \"%s\", the default action assigns an \
266 undefined value to $$\n", myname, lineno, input_file_name);
267 }
268
269 void
270 undefined_goal(char *s)
271 {
272     fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
273     done(1);
274 }
275
276 void
277 undefined_symbol_warning(char *s)
278 {
279     fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
280 }