Code cleanup. Converting a number lexeme to a proper integer setup but not done yet. So number tokens don't have a valid value.

This commit is contained in:
2022-05-05 16:12:33 +00:00
parent 9fa48520c7
commit 8ec0b9b216
11 changed files with 59 additions and 283 deletions
+8 -3
View File
@@ -1,11 +1,16 @@
#include "../includes/token.h"
Token* CreateToken(TokenType type, char* value) {
Token* CreateToken(char* lexeme, void* value, int lineNumber, TokenType type) {
Token* token = calloc(1, sizeof(Token));
if (!token) return NULL;
if (!token) {
fprintf(stderr, "Failed to calloc memory for Token. %s.\n", strerror(errno));
return NULL;
}
token->type = type;
token->line = lineNumber;
token->lexeme = lexeme;
token->value = value;
return token;
@@ -14,7 +19,7 @@ Token* CreateToken(TokenType type, char* value) {
void FreeToken(Token* token) {
if (!token) return;
if (token->value) free(token->value);
if (token->value && token->type >= STRING) free(token->value);
free(token);
}