all repos — xyw @ 0e118986c0cba6735162af0dd869e2d9a20fc906

A minimal virtual machine and assembler for terminals.

Implemented string parsing.
h3rald h3rald@h3rald.com
Wed, 26 Nov 2025 14:17:18 +0100
commit

0e118986c0cba6735162af0dd869e2d9a20fc906

parent

4e537c4129d6d43826468842a3782a42d477fc8b

1 files changed, 61 insertions(+), 0 deletions(-)

jump to
M xywasm.cxywasm.c

@@ -4,6 +4,7 @@

#define TOKEN_MAX_LENGTH 32 #define DIRECTIVE_CONTENT_MAX_LENGTH 256 #define COMMENT_CONTENT_MAX_LENGTH 256 +#define STRING_MAX_LENGTH 256 #define MODE_X 0x20 #define MODE_Y 0x40

@@ -36,6 +37,7 @@ // The token being processed

static char token[TOKEN_MAX_LENGTH]; static unsigned int token_length = 0; +// Directive identifier static char directive[TOKEN_MAX_LENGTH]; static unsigned int directive_length = 0;

@@ -276,6 +278,16 @@ }

return -1; } +static int parse_string(xyw_context *ctx) +{ + (void)ctx; + // Token is a string enclosed in double quotes + // TODO: Remove + printf("String:\t\t%s [directive: %s]\n", token, directive_length > 0 ? directive : "N/A"); + // TODO: Store string data + return 0; +} + static int parse_symbol(xyw_context *ctx) { if (validate_symbol(ctx, token, token_length) != 0)

@@ -323,6 +335,10 @@ else if (token[0] == '%')

{ return parse_binary_number(ctx); } + else if (token[0] == '\"') + { + return parse_string(ctx); + } else if ((token[0] >= '0' && token[0] <= '9') || token[0] == '-') { return parse_decimal_number(ctx);

@@ -352,6 +368,51 @@

unsigned char c; while (fread(&c, 1, 1, ctx->fp) == 1) { + if (c == '"') + { + // Start of string token + if (token_length < STRING_MAX_LENGTH - 1) + { + token[token_length++] = (char)c; + token[token_length] = '\0'; + ctx->column++; + // Read until closing quote + while (fread(&c, 1, 1, ctx->fp) == 1) + { + ctx->column++; + if (token_length < STRING_MAX_LENGTH - 1) + { + token[token_length++] = (char)c; + token[token_length] = '\0'; + } + else + { + token_error("Token too long"); + fclose(ctx->fp); + return -1; + } + if (c == '"') + { + break; + } + } + // Process string token + if (parse_token(ctx) != 0) + { + fclose(ctx->fp); + return -1; + } + token_length = 0; + token[0] = '\0'; + } + else + { + token_error("Token too long"); + fclose(ctx->fp); + return -1; + } + continue; + } if (c > 0x20 && c != 0x7f) // printable non-space { if (token_length < TOKEN_MAX_LENGTH - 1)