aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/lexer.c10
-rw-r--r--asm/lexer.h1
2 files changed, 10 insertions, 1 deletions
diff --git a/asm/lexer.c b/asm/lexer.c
index 7c3f7da..149d717 100644
--- a/asm/lexer.c
+++ b/asm/lexer.c
@@ -43,13 +43,21 @@ bool is_symbol(char c)
return isalpha(c) || c == '-' || c == '_' || c == '.';
}
+char uppercase(char c)
+{
+ if (c >= 'a' && c <= 'z')
+ return (c - 'a') + 'A';
+ return c;
+}
+
token_t tokenise_symbol(buffer_t *buffer)
{
token_t token = {.type = TOKEN_SYMBOL, .str_size = 0};
for (; token.str_size < space_left(buffer) &&
is_symbol(buffer->data[buffer->used + token.str_size]);
++token.str_size)
- continue;
+ buffer->data[buffer->used + token.str_size] =
+ uppercase(buffer->data[buffer->used + token.str_size]);
token.str = calloc(token.str_size + 1, 1);
memcpy(token.str, buffer->data + buffer->used, token.str_size);
token.str[token.str_size] = '\0';
diff --git a/asm/lexer.h b/asm/lexer.h
index b7d00c1..5e8b47b 100644
--- a/asm/lexer.h
+++ b/asm/lexer.h
@@ -31,6 +31,7 @@ typedef struct
typedef darr_t buffer_t;
typedef darr_t token_stream_t;
+#define TOKEN_STREAM_AT(STREAM_DATA, INDEX) (((token_t *)(STREAM_DATA))[INDEX])
const char *token_type_as_cstr(token_type_t type);
token_stream_t tokenise_buffer(buffer_t *);