diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-05-05 14:43:17 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-05-05 14:43:24 +0900 |
| commit | 1699d97db7659d471390d2e173dbca6b35747f68 (patch) | |
| tree | 11cb11bccc79f7b287b318177dfd75fb731f617d /main.c | |
| parent | 171fb430a4dcd2c592d218c95b30a3ef436f865d (diff) | |
| download | P4Dcc-1699d97db7659d471390d2e173dbca6b35747f68.tar.gz P4Dcc-1699d97db7659d471390d2e173dbca6b35747f68.tar.zst P4Dcc-1699d97db7659d471390d2e173dbca6b35747f68.zip | |
support #define that replaces name with identifiers
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -334,16 +334,29 @@ struct Token* tokenize(char* src, int len) { pos += 1; } int start2 = pos; - while (isdigit(src[pos])) { - pos += 1; + int is_digit = isdigit(src[pos]); + if (is_digit) { + while (isdigit(src[pos])) { + pos += 1; + } + } else { + while (isalnum(src[pos]) || src[pos] == '_') { + pos += 1; + } } def->to = calloc(1, sizeof(struct Token)); - def->to->kind = TK_L_INT; + if (is_digit) { + def->to->kind = TK_L_INT; + } else { + def->to->kind = TK_IDENT; + } def->to->value = calloc(pos - start2 + 1, sizeof(char)); memcpy(def->to->value, src + start2, pos - start2); def += 1; } else { - fatal_error("unknown token"); + char* buf = calloc(1024, sizeof(char)); + sprintf(buf, "!!! %d", c); + fatal_error(buf); } } return tokens; |
