diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-11 13:22:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-15 10:06:21 +0900 |
| commit | fd7d82869eb42d086174ec02938b49e4f233c319 (patch) | |
| tree | 326ae533e90594f0caef833ca71b38ad895346d3 /preprocess.c | |
| parent | fc55b5f89b5974f627657c730bfd6b7d01609eae (diff) | |
| download | ducc-fd7d82869eb42d086174ec02938b49e4f233c319.tar.gz ducc-fd7d82869eb42d086174ec02938b49e4f233c319.tar.zst ducc-fd7d82869eb42d086174ec02938b49e4f233c319.zip | |
feat: implement '*=', '/=' and '%=' operators
Diffstat (limited to 'preprocess.c')
| -rw-r--r-- | preprocess.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/preprocess.c b/preprocess.c index b7e52bf..c4b1c16 100644 --- a/preprocess.c +++ b/preprocess.c @@ -13,6 +13,9 @@ enum TokenKind { TokenKind_arrow, TokenKind_assign, TokenKind_assign_add, + TokenKind_assign_div, + TokenKind_assign_mod, + TokenKind_assign_mul, TokenKind_assign_sub, TokenKind_brace_l, TokenKind_brace_r, @@ -111,6 +114,12 @@ const char* token_kind_stringify(TokenKind k) { return "="; else if (k == TokenKind_assign_add) return "+="; + else if (k == TokenKind_assign_div) + return "/="; + else if (k == TokenKind_assign_mod) + return "%="; + else if (k == TokenKind_assign_mul) + return "*="; else if (k == TokenKind_assign_sub) return "-="; else if (k == TokenKind_brace_l) @@ -493,9 +502,17 @@ void pp_tokenize_all(Preprocessor* pp) { tok->kind = TokenKind_minus; } } else if (c == '*') { - tok->kind = TokenKind_star; + if (pp->src[pp->pos] == '=') { + ++pp->pos; + tok->kind = TokenKind_assign_mul; + } else { + tok->kind = TokenKind_star; + } } else if (c == '/') { - if (pp->src[pp->pos] == '/') { + if (pp->src[pp->pos] == '=') { + ++pp->pos; + tok->kind = TokenKind_assign_div; + } else if (pp->src[pp->pos] == '/') { start = pp->pos - 1; ++pp->pos; while (pp->src[pp->pos] && pp->src[pp->pos] != '\n' && pp->src[pp->pos] != '\r') { @@ -524,7 +541,12 @@ void pp_tokenize_all(Preprocessor* pp) { tok->kind = TokenKind_slash; } } else if (c == '%') { - tok->kind = TokenKind_percent; + if (pp->src[pp->pos] == '=') { + ++pp->pos; + tok->kind = TokenKind_assign_mod; + } else { + tok->kind = TokenKind_percent; + } } else if (c == '.') { if (pp->src[pp->pos] == '.') { ++pp->pos; |
