Fixed a bug where the tokenizer wasn't parsing hexadecimal numbers correctly. Added support for tokenizing the colon and comma characters.

This commit is contained in:
2025-01-08 23:22:43 -06:00
parent 428d674f54
commit ebfd7cf94c
6 changed files with 86 additions and 21 deletions
+26 -9
View File
@@ -11,26 +11,43 @@ struct _token* TokenCreate(TokenType type, int lineNumber, int columnNumber, boo
return token;
}
char* TokenStringify(const struct _token* token, bool valueOnly) {
if (!token) return NULL;
char buffer[32];
char* TokenStringify(const struct _token* token) {
if (!token) return false;
char* buffer = NULL;
switch(token->Type) {
case Empty:
return "<>";
case String:
case Symbol:
return token->Value.String;
buffer = calloc(strlen(token->Value.String) + 1, sizeof(char));
strncpy(buffer, token->Value.String, strlen(token->Value.String));
break;
case Empty:
buffer = calloc(8, sizeof(char));
strncpy(buffer, "<>", sizeof(char) * 2);
break;
case Number:
buffer = calloc(32, sizeof(char));
sprintf(buffer, "%d", token->Value.Number);
break;
case LineEnd:
return "\n";
buffer = calloc(8, sizeof(char));
strncpy(buffer, "\n", sizeof(char));
break;
case FileEnd:
return NULL;
break;
default:
strncpy(buffer, token->Value.Operator, 8);
buffer = calloc(16, sizeof(char));
strncpy(buffer, token->Value.Operator, sizeof(char));
break;
}