3 /* Copyright (c) 1994 Stanford University
7 This software is provided under the terms described in
8 the "suif_copyright.h" include file. */
10 #include <suif_copyright.h>
12 /* snoot error reporting */
16 int errcnt
; /* number of compilation errors */
17 int errlimit
= 20; /* compilation error limit */
18 boolean wflag
; /* TRUE to suppress warning messages */
20 static void printtoken(void);
22 /* error - issue error message */
23 void error(const char *fmt
, ...)
28 if ((firstfile
!= file
) && (firstfile
!= NULL
) && (*firstfile
!= 0))
29 fprint(stderr
, "%s: ", firstfile
);
30 fprint(stderr
, "%w: ", &src
);
31 vfprint(stderr
, fmt
, ap
);
32 if (++errcnt
>= errlimit
)
35 error("too many errors\n");
41 /* expect - advance if t is tok, otherwise issue message */
50 error("syntax error; found");
52 fprint(stderr
, " expecting `%k'\n", tok
);
57 /* fatal - issue fatal error message and exit */
58 int fatal(const char *name
, const char *fmt
, int n
)
62 error("compiler error in %s--", name
);
63 fprint(stderr
, fmt
, n
);
68 /* printtoken - print current token preceeded by a space */
69 static void printtoken(void)
74 fprint(stderr
, " `%s'", token
); break;
81 for (s
= token
; (*s
!= 0) && (s
- token
< 20); s
++)
83 if (*s
< ' ' || *s
>= 0177)
84 fprint(stderr
, "\\%o", *s
);
86 fprint(stderr
, "%c", *s
);
89 fprint(stderr
, " ...");
91 fprint(stderr
, "%c", *token
);
93 } /* else fall through */
98 fprint(stderr
, " `%s'", token
);
104 fprint(stderr
, " \"%k\"", t
);
107 fprint(stderr
, " `%k'", t
);
111 /* skipto - skip input up to tok U set, for a token where kind[t] is in set */
112 void skipto(int tok
, char set
[])
117 for (n
= 0; (t
!= EOI
) && (t
!= tok
); t
= gettok())
121 for (s
= set
; (*s
!= 0) && (kind
[t
] != *s
); s
++)
129 error("skipping", 0, 0, 0, 0);
134 fprint(stderr
, " ...\n");
139 error("up to", 0, 0, 0, 0);
143 fprint(stderr
, "\n");
146 /* test - check for token tok, skip to tok U set, if necessary */
147 void test(int tok
, char set
[])
162 /* warning - issue warning error message */
163 void warning(const char *fmt
, ...)
170 errcnt
--; /* compensate for increment in error */
172 vfprint(stderr
, fmt
, ap
);