From dca51106a205a14380446705d68a12d810eeb20f Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 26 Oct 2023 11:17:01 +0100 Subject: Added support in lexer for negative numbers Though we deal with unsigned numbers internally, it should be possible to read and manipulate negative numbers through 2s complement. Later on we'll add support for signed operations via 2s complement, so this should be allowed. --- asm/lexer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'asm') diff --git a/asm/lexer.c b/asm/lexer.c index 149d717..40b1748 100644 --- a/asm/lexer.c +++ b/asm/lexer.c @@ -68,6 +68,8 @@ token_t tokenise_symbol(buffer_t *buffer) token_t tokenise_number_literal(buffer_t *buffer) { token_t token = {.type = TOKEN_LITERAL_NUMBER, .str_size = 0}; + if (buffer->data[buffer->used] == '-') + ++token.str_size; for (; token.str_size < space_left(buffer) && isdigit(buffer->data[buffer->used + token.str_size]); ++token.str_size) @@ -105,7 +107,8 @@ token_stream_t tokenise_buffer(buffer_t *buffer) continue; is_token = false; } - else if (isdigit(c)) + else if (isdigit(c) || (space_left(buffer) > 1 && c == '-' && + isdigit(buffer->data[buffer->used + 1]))) t = tokenise_number_literal(buffer); else if (is_symbol(c)) t = tokenise_symbol(buffer); -- cgit v1.2.3-13-gbd6f