-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.c
49 lines (41 loc) · 1016 Bytes
/
misc.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
45
46
47
48
49
#include "defs.h"
#include "data.h"
#include "decl.h"
// Miscellaneous functions
// Copyright (c) 2019 Warren Toomey, GPL3
// Ensure that the current token is t,
// and fetch the next token. Otherwise,
// throw an error
void match(int t, char* what) {
if (Token.token == t) {
scan(&Token);
} else {
printf("%s expected on line %d\n", what, Line);
exit(1);
}
}
// Match a semicolon and fetch the next token
void semi(void) {
match(T_SEMI, ";");
}
// Match an identifier and fetch the next token
void ident(void) {
match(T_IDENT, "identifier");
}
// Print out fatal messages
void fatal(char* s) {
fprintf(stderr, "%s on line %d\n", s, Line);
exit(1);
}
void fatals(char* s1, char* s2) {
fprintf(stderr, "%s:%s on line %d\n", s1, s2, Line);
exit(1);
}
void fatald(char* s, int d) {
fprintf(stderr, "%s:%d on line %d\n", s, d, Line);
exit(1);
}
void fatalc(char* s, int c) {
fprintf(stderr, "%s:%c on line %d\n", s, c, Line);
exit(1);
}