-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.c
44 lines (39 loc) · 1.08 KB
/
error.c
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
#include "header.h"
#include "std.h"
#include "std_io.h"
_Noreturn void error_unexpected_token(const struct Token *tokvec,
const char *str)
{
fprintf(stderr, "Unexpected token: `");
print_token_at(tokvec);
fprintf(stderr, "` while expecting %s. \n", str);
fprintf(stderr, "Next token: `");
print_token_at(tokvec + 1);
fprintf(stderr, "`\n");
fprintf(stderr, "Previous token: `");
print_token_at(tokvec - 1);
/* it does not fail if tokvec[0] was the
first token, since there always is at least one token (BEGINNING) */
fprintf(stderr, "`\n");
exit(EXIT_FAILURE);
}
_Noreturn void simple_error(const char *str)
{
fprintf(stderr, "%s", str);
exit(EXIT_FAILURE);
}
void expect_and_consume(const struct Token **ptr_tokvec, enum TokenKind kind,
const char *str)
{
const struct Token *tokvec = *ptr_tokvec;
if (tokvec[0].kind != kind) {
error_unexpected_token(tokvec, str);
}
++tokvec;
*ptr_tokvec = tokvec;
}
_Noreturn void unsupported(const char *str)
{
fprintf(stderr, "unsupported: %s\n", str);
exit(EXIT_FAILURE);
}