diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-26 11:17:01 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-26 11:17:01 +0100 |
commit | dca51106a205a14380446705d68a12d810eeb20f (patch) | |
tree | eebb7fbcf9af5b37859a9558387010c6dd3aba4e /asm/lexer.c | |
parent | e9c54e045af7db5623ee713a81aae5cc745f9ab6 (diff) | |
download | ovm-dca51106a205a14380446705d68a12d810eeb20f.tar.gz ovm-dca51106a205a14380446705d68a12d810eeb20f.tar.bz2 ovm-dca51106a205a14380446705d68a12d810eeb20f.zip |
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.
Diffstat (limited to 'asm/lexer.c')
-rw-r--r-- | asm/lexer.c | 5 |
1 files changed, 4 insertions, 1 deletions
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); |