139775Sbostic /*
239775Sbostic * Copyright (c) 1989 The Regents of the University of California.
339775Sbostic * All rights reserved.
439775Sbostic *
539775Sbostic * This code is derived from software contributed to Berkeley by
639775Sbostic * Robert Paul Corbett.
739775Sbostic *
8*42698Sbostic * %sccs.include.redist.c%
939775Sbostic */
1039775Sbostic
1139775Sbostic #ifndef lint
12*42698Sbostic static char sccsid[] = "@(#)error.c 5.3 (Berkeley) 06/01/90";
1339775Sbostic #endif /* not lint */
1439775Sbostic
1539775Sbostic /* routines for printing error messages */
1639775Sbostic
1739775Sbostic #include "defs.h"
1839775Sbostic
1939775Sbostic
fatal(msg)2039775Sbostic fatal(msg)
2139775Sbostic char *msg;
2239775Sbostic {
2339775Sbostic fprintf(stderr, "%s: f - %s\n", myname, msg);
2439775Sbostic done(2);
2539775Sbostic }
2639775Sbostic
2739775Sbostic
no_space()2839775Sbostic no_space()
2939775Sbostic {
3039775Sbostic fprintf(stderr, "%s: f - out of space\n", myname);
3139775Sbostic done(2);
3239775Sbostic }
3339775Sbostic
3439775Sbostic
open_error(filename)3539775Sbostic open_error(filename)
3639775Sbostic char *filename;
3739775Sbostic {
3839775Sbostic fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
3939775Sbostic done(2);
4039775Sbostic }
4139775Sbostic
4239775Sbostic
unexpected_EOF()4339775Sbostic unexpected_EOF()
4439775Sbostic {
4539775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
4639775Sbostic myname, lineno, input_file_name);
4739775Sbostic done(1);
4839775Sbostic }
4939775Sbostic
5039775Sbostic
print_pos(st_line,st_cptr)5139775Sbostic print_pos(st_line, st_cptr)
5239775Sbostic char *st_line;
5339775Sbostic char *st_cptr;
5439775Sbostic {
5539775Sbostic register char *s;
5639775Sbostic
5739775Sbostic if (st_line == 0) return;
5839775Sbostic for (s = st_line; *s != '\n'; ++s)
5939775Sbostic {
6039775Sbostic if (isprint(*s) || *s == '\t')
6139775Sbostic putc(*s, stderr);
6239775Sbostic else
6339775Sbostic putc('?', stderr);
6439775Sbostic }
6539775Sbostic putc('\n', stderr);
6639775Sbostic for (s = st_line; s < st_cptr; ++s)
6739775Sbostic {
6839775Sbostic if (*s == '\t')
6939775Sbostic putc('\t', stderr);
7039775Sbostic else
7139775Sbostic putc(' ', stderr);
7239775Sbostic }
7339775Sbostic putc('^', stderr);
7439775Sbostic putc('\n', stderr);
7539775Sbostic }
7639775Sbostic
7739775Sbostic
syntax_error(st_lineno,st_line,st_cptr)7839775Sbostic syntax_error(st_lineno, st_line, st_cptr)
7939775Sbostic int st_lineno;
8039775Sbostic char *st_line;
8139775Sbostic char *st_cptr;
8239775Sbostic {
8339775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
8439775Sbostic myname, st_lineno, input_file_name);
8539775Sbostic print_pos(st_line, st_cptr);
8639775Sbostic done(1);
8739775Sbostic }
8839775Sbostic
8939775Sbostic
unterminated_comment(c_lineno,c_line,c_cptr)9039775Sbostic unterminated_comment(c_lineno, c_line, c_cptr)
9139775Sbostic int c_lineno;
9239775Sbostic char *c_line;
9339775Sbostic char *c_cptr;
9439775Sbostic {
9539775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
9639775Sbostic myname, c_lineno, input_file_name);
9739775Sbostic print_pos(c_line, c_cptr);
9839775Sbostic done(1);
9939775Sbostic }
10039775Sbostic
10139775Sbostic
unterminated_string(s_lineno,s_line,s_cptr)10239775Sbostic unterminated_string(s_lineno, s_line, s_cptr)
10339775Sbostic int s_lineno;
10439775Sbostic char *s_line;
10539775Sbostic char *s_cptr;
10639775Sbostic {
10739775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
10839775Sbostic myname, s_lineno, input_file_name);
10939775Sbostic print_pos(s_line, s_cptr);
11039775Sbostic done(1);
11139775Sbostic }
11239775Sbostic
11339775Sbostic
unterminated_text(t_lineno,t_line,t_cptr)11439775Sbostic unterminated_text(t_lineno, t_line, t_cptr)
11539775Sbostic int t_lineno;
11639775Sbostic char *t_line;
11739775Sbostic char *t_cptr;
11839775Sbostic {
11939775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
12039775Sbostic myname, t_lineno, input_file_name);
12139775Sbostic print_pos(t_line, t_cptr);
12239775Sbostic done(1);
12339775Sbostic }
12439775Sbostic
12539775Sbostic
unterminated_union(u_lineno,u_line,u_cptr)12639775Sbostic unterminated_union(u_lineno, u_line, u_cptr)
12739775Sbostic int u_lineno;
12839775Sbostic char *u_line;
12939775Sbostic char *u_cptr;
13039775Sbostic {
13139775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
13239775Sbostic declaration\n", myname, u_lineno, input_file_name);
13339775Sbostic print_pos(u_line, u_cptr);
13439775Sbostic done(1);
13539775Sbostic }
13639775Sbostic
13739775Sbostic
over_unionized(u_cptr)13839775Sbostic over_unionized(u_cptr)
13939775Sbostic char *u_cptr;
14039775Sbostic {
14139775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
14239775Sbostic declarations\n", myname, lineno, input_file_name);
14339775Sbostic print_pos(line, u_cptr);
14439775Sbostic done(1);
14539775Sbostic }
14639775Sbostic
14739775Sbostic
illegal_tag(t_lineno,t_line,t_cptr)14839775Sbostic illegal_tag(t_lineno, t_line, t_cptr)
14939775Sbostic int t_lineno;
15039775Sbostic char *t_line;
15139775Sbostic char *t_cptr;
15239775Sbostic {
15339775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
15439775Sbostic myname, t_lineno, input_file_name);
15539775Sbostic print_pos(t_line, t_cptr);
15639775Sbostic done(1);
15739775Sbostic }
15839775Sbostic
15939775Sbostic
illegal_character(c_cptr)16039775Sbostic illegal_character(c_cptr)
16139775Sbostic char *c_cptr;
16239775Sbostic {
16339775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
16439775Sbostic myname, lineno, input_file_name);
16539775Sbostic print_pos(line, c_cptr);
16639775Sbostic done(1);
16739775Sbostic }
16839775Sbostic
16939775Sbostic
used_reserved(s)17039775Sbostic used_reserved(s)
17139775Sbostic char *s;
17239775Sbostic {
17339775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \
17439775Sbostic %s\n", myname, lineno, input_file_name, s);
17539775Sbostic done(1);
17639775Sbostic }
17739775Sbostic
17839775Sbostic
tokenized_start(s)17939775Sbostic tokenized_start(s)
18039775Sbostic char *s;
18139775Sbostic {
18239775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
18339775Sbostic declared to be a token\n", myname, lineno, input_file_name, s);
18439775Sbostic done(1);
18539775Sbostic }
18639775Sbostic
18739775Sbostic
retyped_warning(s)18839775Sbostic retyped_warning(s)
18939775Sbostic char *s;
19039775Sbostic {
19139775Sbostic fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
19239775Sbostic redeclared\n", myname, lineno, input_file_name, s);
19339775Sbostic }
19439775Sbostic
19539775Sbostic
reprec_warning(s)19639775Sbostic reprec_warning(s)
19739775Sbostic char *s;
19839775Sbostic {
19939775Sbostic fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
20039775Sbostic redeclared\n", myname, lineno, input_file_name, s);
20139775Sbostic }
20239775Sbostic
20339775Sbostic
revalued_warning(s)20439775Sbostic revalued_warning(s)
20539775Sbostic char *s;
20639775Sbostic {
20739775Sbostic fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
20839775Sbostic redeclared\n", myname, lineno, input_file_name, s);
20939775Sbostic }
21039775Sbostic
21139775Sbostic
terminal_start(s)21239775Sbostic terminal_start(s)
21339775Sbostic char *s;
21439775Sbostic {
21539775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
21639775Sbostic token\n", myname, lineno, input_file_name, s);
21739775Sbostic done(1);
21839775Sbostic }
21939775Sbostic
22039775Sbostic
restarted_warning()22139775Sbostic restarted_warning()
22239775Sbostic {
22339775Sbostic fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
22439775Sbostic redeclared\n", myname, lineno, input_file_name);
22539775Sbostic }
22639775Sbostic
22739775Sbostic
no_grammar()22839775Sbostic no_grammar()
22939775Sbostic {
23039775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
23139775Sbostic specified\n", myname, lineno, input_file_name);
23239775Sbostic done(1);
23339775Sbostic }
23439775Sbostic
23539775Sbostic
terminal_lhs(s_lineno)23639775Sbostic terminal_lhs(s_lineno)
23739775Sbostic int s_lineno;
23839775Sbostic {
23939775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
24039775Sbostic of a production\n", myname, s_lineno, input_file_name);
24139775Sbostic done(1);
24239775Sbostic }
24339775Sbostic
24439775Sbostic
prec_redeclared()24539775Sbostic prec_redeclared()
24639775Sbostic {
24739775Sbostic fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \
24839775Sbostic specifiers\n", myname, lineno, input_file_name);
24939775Sbostic }
25039775Sbostic
25139775Sbostic
unterminated_action(a_lineno,a_line,a_cptr)25239775Sbostic unterminated_action(a_lineno, a_line, a_cptr)
25339775Sbostic int a_lineno;
25439775Sbostic char *a_line;
25539775Sbostic char *a_cptr;
25639775Sbostic {
25739775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
25839775Sbostic myname, a_lineno, input_file_name);
25939775Sbostic print_pos(a_line, a_cptr);
26039775Sbostic done(1);
26139775Sbostic }
26239775Sbostic
26339775Sbostic
dollar_warning(a_lineno,i)26439775Sbostic dollar_warning(a_lineno, i)
26539775Sbostic int a_lineno;
26639775Sbostic int i;
26739775Sbostic {
26839775Sbostic fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
26939775Sbostic end of the current rule\n", myname, a_lineno, input_file_name, i);
27039775Sbostic }
27139775Sbostic
27239775Sbostic
dollar_error(a_lineno,a_line,a_cptr)27339775Sbostic dollar_error(a_lineno, a_line, a_cptr)
27439775Sbostic int a_lineno;
27539775Sbostic char *a_line;
27639775Sbostic char *a_cptr;
27739775Sbostic {
27839775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
27939775Sbostic myname, a_lineno, input_file_name);
28039775Sbostic print_pos(a_line, a_cptr);
28139775Sbostic done(1);
28239775Sbostic }
28339775Sbostic
28439775Sbostic
untyped_lhs()28539775Sbostic untyped_lhs()
28639775Sbostic {
28739775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
28839775Sbostic myname, lineno, input_file_name);
28939775Sbostic done(1);
29039775Sbostic }
29139775Sbostic
29239775Sbostic
untyped_rhs(i,s)29339775Sbostic untyped_rhs(i, s)
29439775Sbostic int i;
29539775Sbostic char *s;
29639775Sbostic {
29739775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
29839775Sbostic myname, lineno, input_file_name, i, s);
29939775Sbostic done(1);
30039775Sbostic }
30139775Sbostic
30239775Sbostic
unknown_rhs(i)30339775Sbostic unknown_rhs(i)
30439775Sbostic int i;
30539775Sbostic {
30639775Sbostic fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
30739775Sbostic myname, lineno, input_file_name, i);
30839775Sbostic done(1);
30939775Sbostic }
31039775Sbostic
31139775Sbostic
default_action_warning()31239775Sbostic default_action_warning()
31339775Sbostic {
31439775Sbostic fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
31539775Sbostic undefined value to $$\n", myname, lineno, input_file_name);
31639775Sbostic }
31739775Sbostic
31839775Sbostic
undefined_goal(s)31939775Sbostic undefined_goal(s)
32039775Sbostic char *s;
32139775Sbostic {
32239775Sbostic fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
32339775Sbostic done(1);
32439775Sbostic }
32539775Sbostic
32639775Sbostic
undefined_symbol_warning(s)32739775Sbostic undefined_symbol_warning(s)
32839775Sbostic char *s;
32939775Sbostic {
33039775Sbostic fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
33139775Sbostic }
332