diff options
-rw-r--r-- | asm/lexer.c | 22 | ||||
-rw-r--r-- | asm/lexer.h | 1 | ||||
-rw-r--r-- | asm/parser.c | 1 |
3 files changed, 24 insertions, 0 deletions
diff --git a/asm/lexer.c b/asm/lexer.c index 49756f5..5218d16 100644 --- a/asm/lexer.c +++ b/asm/lexer.c @@ -34,6 +34,8 @@ const char *token_type_as_cstr(token_type_t type) return "GLOBAL"; case TOKEN_STAR: return "STAR"; + case TOKEN_LITERAL_STRING: + return "LITERAL_STRING"; case TOKEN_LITERAL_NUMBER: return "LITERAL_NUMBER"; case TOKEN_LITERAL_CHAR: @@ -461,6 +463,24 @@ token_t tokenise_char_literal(buffer_t *buffer, size_t *column) return token; } +token_t tokenise_string_literal(buffer_t *buffer, size_t *column) +{ + ++buffer->used; + size_t string_size; + for (string_size = 0; string_size + buffer->used < buffer->available && + buffer->data[buffer->used + string_size] != '\"'; + ++string_size) + continue; + token_t t = {.type = TOKEN_LITERAL_STRING, + .column = *column, + .str = malloc(string_size + 1), + .str_size = string_size}; + memcpy(t.str, buffer->data + (buffer->used - string_size), string_size); + t.str[string_size] = '\0'; + *column += string_size + 1; + return t; +} + lerr_t tokenise_buffer(buffer_t *buffer, token_stream_t *tokens_ptr) { size_t column = 0, line = 1; @@ -507,6 +527,8 @@ lerr_t tokenise_buffer(buffer_t *buffer, token_stream_t *tokens_ptr) t.str[0] = '\0'; ++buffer->used; } + else if (c == '\"') + t = tokenise_string_literal(buffer, &column); else if (isdigit(c) || (space_left(buffer) > 1 && c == '-' && isdigit(buffer->data[buffer->used + 1]))) t = tokenise_number_literal(buffer, &column); diff --git a/asm/lexer.h b/asm/lexer.h index 8d62440..432acaf 100644 --- a/asm/lexer.h +++ b/asm/lexer.h @@ -24,6 +24,7 @@ typedef enum TokenType TOKEN_STAR, TOKEN_LITERAL_NUMBER, TOKEN_LITERAL_CHAR, + TOKEN_LITERAL_STRING, TOKEN_NOOP, TOKEN_HALT, TOKEN_PUSH, diff --git a/asm/parser.c b/asm/parser.c index 282a6c5..421c721 100644 --- a/asm/parser.c +++ b/asm/parser.c @@ -469,6 +469,7 @@ perr_t parse_next(token_stream_t *stream, presult_t *ret) perr_t perr = PERR_OK; switch (token.type) { + case TOKEN_LITERAL_STRING: case TOKEN_PP_CONST: case TOKEN_PP_REFERENCE: case TOKEN_PP_END: |