This commit is contained in:
Yaossg 2024-11-16 08:39:45 +08:00
parent 6c8e15ba66
commit f197671868
3 changed files with 10 additions and 12 deletions

View File

@ -13,7 +13,3 @@ int eprintf(const char format[], ...) {
void ungetchar(int ch) {
ungetc(ch, stdin);
}
int eof() {
return feof(stdin);
}

View File

@ -8,5 +8,4 @@ void exit(int status);
// ext
void ungetchar(int ch);
int eof();
int eprintf(const char* format, ...);

13
boot.c
View File

@ -72,7 +72,7 @@ const int TOKEN_STRING = 150;
int parse_int(int ch) {
int num = ch - '0';
while (!eof() && is_digit(ch = getchar())) {
while (is_digit(ch = getchar())) {
num = num * 10;
num = num + ch - '0';
}
@ -118,7 +118,11 @@ int string_lut_size;
int parse_string() {
int offset = string_offset;
int ch;
while (!eof() && (ch = getchar()) != '"') {
while ((ch = getchar()) != '"') {
if (ch == -1 || ch == '\n') {
eprintf("expecting '\"'\n");
exit(1);
}
if (ch == '\\') {
ch = get_escaped_char();
}
@ -136,7 +140,7 @@ int id_lut_size;
int parse_id(int ch) {
int offset = id_offset;
id_table[id_offset++] = ch;
while (!eof() && is_id_cont(ch = getchar())) {
while (is_id_cont(ch = getchar())) {
id_table[id_offset++] = ch;
}
ungetchar(ch);
@ -1278,6 +1282,7 @@ void parse_top_level() {
eprintf("unexpected token: %d\n", token_type);
exit(1);
}
parse_top_level();
}
void dump_string_table() {
@ -1311,9 +1316,7 @@ void dump_string_table() {
}
int main() {
while (!eof()) {
parse_top_level();
}
dump_string_table();
return 0;
}