1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
/*
* routines for printing error messages
*/
#include "defs.h"
#include <stdarg.h>
extern FILE *inc_file;
extern char inc_file_name[];
void FileError(char *fmt, ...);
/*
* VM: print error message with file coordinates.
* Do it in style acceptable to emacs.
*/
void FileError(char *fmt, ...) {
va_list args;
fprintf(stderr, "%s:%d: ", (inc_file?inc_file_name:input_file_name), lineno);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
}
void fatal(char *msg)
{
fprintf(stderr, "fatal - %s\n", msg);
done(2);
}
void no_space()
{
fprintf(stderr, "fatal - out of space\n");
done(2);
}
void open_error(char *filename)
{
fprintf(stderr, "fatal - cannot open \"%s\"\n", filename);
done(2);
}
void unexpected_EOF()
{
FileError("unexpected end-of-file");
done(1);
}
void print_pos(char *st_line, char *st_cptr)
{
register char *s;
if (st_line == 0) return;
for (s = st_line; *s != '\n'; ++s)
{
if (isprint(*s) || *s == '\t')
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);
}
int read_errs = 0;
void error(int lineno, char *line, char *cptr, char *msg, ...)
{
char sbuf[512];
va_list args;
va_start(args, msg);
vsprintf(sbuf, msg, args);
va_end(args);
FileError("%s", sbuf);
read_errs++;
}
void syntax_error(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "syntax error");
exit(1);
}
void unterminated_comment(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "unmatched /*");
exit(1);
}
void unterminated_string(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "unterminated string");
exit(1);
}
void unterminated_text(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "unmatched %%{");
exit(1);
}
void unterminated_union(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "unterminated %%union");
exit(1);
}
void over_unionized(char *cptr) {
error(lineno, line, cptr, "too many %%union declarations");
exit(1);
}
void illegal_tag(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "illegal tag");
}
void illegal_character(char *cptr) {
error(lineno, line, cptr, "illegal character");
}
void used_reserved(char *s) {
error(lineno, 0, 0, "illegal use of reserved symbol %s", s);
}
void tokenized_start(char *s) {
error(lineno, 0, 0, "the start symbol %s cannot be declared to be a token", s);
}
void retyped_warning(char *s) {
FileError("the type of %s has been redeclared", s);
}
void reprec_warning(char *s) {
FileError("the precedence of %s has been redeclared", s);
}
void revalued_warning(char *s) {
FileError("the value of %s has been redeclared", s);
}
void terminal_start(char *s) {
error(lineno, 0, 0, "the start symbol %s is a token", s);
}
void restarted_warning() {
FileError("the start symbol has been redeclared");
}
void no_grammar() {
error(lineno, 0, 0, "no grammar has been specified");
}
void terminal_lhs(int lineno) {
error(lineno, 0, 0, "a token appears on the lhs of a production");
}
void prec_redeclared() {
error(lineno, 0, 0, "conflicting %%prec specifiers");
}
void unterminated_action(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "unterminated action");
}
void unterminated_arglist(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "unterminated argument list");
}
void bad_formals() {
error(lineno, 0, 0, "bad formal argument list");
}
void dollar_warning(int a_lineno, int i) {
int slineno = lineno;
lineno = a_lineno;
FileError("$%d references beyond the end of the current rule", i);
lineno = slineno;
}
void dollar_error(int lineno, char *line, char *cptr) {
error(lineno, line, cptr, "illegal $-name");
}
void untyped_lhs() {
error(lineno, 0, 0, "$$ is untyped");
}
void untyped_rhs(int i, char *s) {
error(lineno, 0, 0, "$%d (%s) is untyped", i, s);
}
void unknown_rhs(int i) {
error(lineno, 0, 0, "$%d is untyped (out of range)", i);
}
void default_action_warning() {
FileError("the default action assigns an undefined value to $$");
}
void undefined_goal(char *s) {
error(lineno, 0, 0, "the start symbol %s is undefined", s);
}
void undefined_symbol_warning(char *s) {
fprintf(stderr, "warning - the symbol %s is undefined\n", s);
}
|