minix/external/bsd/byacc/dist/error.c

293 lines
6.3 KiB
C
Raw Normal View History

2012-06-06 15:25:48 +02:00
/* $NetBSD: error.c,v 1.7 2011/09/10 21:29:04 christos Exp $ */
/* Id: error.c,v 1.9 2011/09/05 23:27:43 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
2012-06-06 15:25:48 +02:00
__RCSID("$NetBSD: error.c,v 1.7 2011/09/10 21:29:04 christos Exp $");
2005-04-21 16:53:53 +02:00
/* routines for printing error messages */
__dead void
fatal(const char *msg)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: f - %s\n", myname, msg);
done(2);
}
__dead void
no_space(void)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: f - out of space\n", myname);
done(2);
}
__dead void
open_error(const char *filename)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
done(2);
}
2012-06-06 15:25:48 +02:00
void
missing_brace(void)
{
fprintf(stderr, "%s: e - line %d of \"%s\", missing '}'\n",
myname, lineno, input_file_name);
done(1);
}
void
unexpected_EOF(void)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
myname, lineno, input_file_name);
done(1);
}
2012-06-06 15:25:48 +02:00
static void
print_pos(char *st_line, char *st_cptr)
2005-04-21 16:53:53 +02:00
{
char *s;
2005-04-21 16:53:53 +02:00
2012-06-06 15:25:48 +02:00
if (st_line == 0)
return;
2005-04-21 16:53:53 +02:00
for (s = st_line; *s != '\n'; ++s)
{
2012-06-06 15:25:48 +02:00
if (isprint(UCH(*s)) || *s == '\t')
2005-04-21 16:53:53 +02:00
putc(*s, stderr);
else
putc('?', stderr);
}
putc('\n', stderr);
for (s = st_line; s < st_cptr; ++s)
{
if (*s == '\t')
putc('\t', stderr);
else
putc(' ', stderr);
}
putc('^', stderr);
putc('\n', stderr);
}
__dead void
syntax_error(int st_lineno, char *st_line, char *st_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
myname, st_lineno, input_file_name);
print_pos(st_line, st_cptr);
done(1);
}
__dead void
unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
myname, c_lineno, input_file_name);
print_pos(c_line, c_cptr);
done(1);
}
__dead void
unterminated_string(int s_lineno, char *s_line, char *s_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
myname, s_lineno, input_file_name);
print_pos(s_line, s_cptr);
done(1);
}
__dead void
unterminated_text(int t_lineno, char *t_line, char *t_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
myname, t_lineno, input_file_name);
print_pos(t_line, t_cptr);
done(1);
}
__dead void
unterminated_union(int u_lineno, char *u_line, char *u_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
declaration\n", myname, u_lineno, input_file_name);
print_pos(u_line, u_cptr);
done(1);
}
__dead void
over_unionized(char *u_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
declarations\n", myname, lineno, input_file_name);
print_pos(line, u_cptr);
done(1);
}
__dead void
illegal_tag(int t_lineno, char *t_line, char *t_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
myname, t_lineno, input_file_name);
print_pos(t_line, t_cptr);
done(1);
}
__dead void
illegal_character(char *c_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
myname, lineno, input_file_name);
print_pos(line, c_cptr);
done(1);
}
__dead void
used_reserved(char *s)
2005-04-21 16:53:53 +02:00
{
2012-06-06 15:25:48 +02:00
fprintf(stderr,
"%s: e - line %d of \"%s\", illegal use of reserved symbol \
2005-04-21 16:53:53 +02:00
%s\n", myname, lineno, input_file_name, s);
done(1);
}
__dead void
tokenized_start(char *s)
2005-04-21 16:53:53 +02:00
{
2012-06-06 15:25:48 +02:00
fprintf(stderr,
"%s: e - line %d of \"%s\", the start symbol %s cannot be \
2005-04-21 16:53:53 +02:00
declared to be a token\n", myname, lineno, input_file_name, s);
2012-06-06 15:25:48 +02:00
done(1);
2005-04-21 16:53:53 +02:00
}
void
retyped_warning(char *s)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
redeclared\n", myname, lineno, input_file_name, s);
}
void
reprec_warning(char *s)
2005-04-21 16:53:53 +02:00
{
2012-06-06 15:25:48 +02:00
fprintf(stderr,
"%s: w - line %d of \"%s\", the precedence of %s has been \
2005-04-21 16:53:53 +02:00
redeclared\n", myname, lineno, input_file_name, s);
}
void
revalued_warning(char *s)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
redeclared\n", myname, lineno, input_file_name, s);
}
2012-06-06 15:25:48 +02:00
void
terminal_start(char *s)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
token\n", myname, lineno, input_file_name, s);
done(1);
}
void
restarted_warning(void)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
redeclared\n", myname, lineno, input_file_name);
}
2012-06-06 15:25:48 +02:00
void
no_grammar(void)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
specified\n", myname, lineno, input_file_name);
done(1);
}
2012-06-06 15:25:48 +02:00
void
terminal_lhs(int s_lineno)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
of a production\n", myname, s_lineno, input_file_name);
done(1);
}
void
prec_redeclared(void)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \
specifiers\n", myname, lineno, input_file_name);
}
2012-06-06 15:25:48 +02:00
void
unterminated_action(int a_lineno, char *a_line, char *a_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
myname, a_lineno, input_file_name);
print_pos(a_line, a_cptr);
done(1);
}
void
dollar_warning(int a_lineno, int i)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
end of the current rule\n", myname, a_lineno, input_file_name, i);
}
__dead void
dollar_error(int a_lineno, char *a_line, char *a_cptr)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
myname, a_lineno, input_file_name);
print_pos(a_line, a_cptr);
done(1);
}
__dead void
untyped_lhs(void)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
myname, lineno, input_file_name);
done(1);
}
__dead void
untyped_rhs(int i, char *s)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
myname, lineno, input_file_name, i, s);
done(1);
}
__dead void
unknown_rhs(int i)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
myname, lineno, input_file_name, i);
done(1);
}
void
default_action_warning(void)
2005-04-21 16:53:53 +02:00
{
2012-06-06 15:25:48 +02:00
fprintf(stderr,
"%s: w - line %d of \"%s\", the default action assigns an \
2005-04-21 16:53:53 +02:00
undefined value to $$\n", myname, lineno, input_file_name);
}
2012-06-06 15:25:48 +02:00
void
undefined_goal(char *s)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
done(1);
}
void
undefined_symbol_warning(char *s)
2005-04-21 16:53:53 +02:00
{
fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
}