Updated the token to more reflect what was implemented in the book. Maybe not the right way to handle it but perhaps this setup will come in handy in later chapters.

This commit is contained in:
2022-03-03 19:39:12 +00:00
parent caf4f02428
commit 5ea8079090
3 changed files with 33 additions and 27 deletions
+6 -2
View File
@@ -15,7 +15,7 @@ KeyValuePair TokenTypeMappings[TOKENTYPE_MAPPINGS_COUNT] = {
const char* GetLexemeMapping(TokenType);
Token* CreateToken(const char* lexeme, int line, TokenType type) {
Token* CreateToken(const char* lexeme, void* literal, int line, TokenType type) {
Token* token = calloc(1, sizeof(Token));
if (!token) {
@@ -23,7 +23,10 @@ Token* CreateToken(const char* lexeme, int line, TokenType type) {
return NULL;
}
if (lexeme) token->lexeme = lexeme;
if (lexeme) {
token->literal = literal;
token->lexeme = lexeme;
}
else {
const char* mapping_result = GetLexemeMapping(type);
@@ -33,6 +36,7 @@ Token* CreateToken(const char* lexeme, int line, TokenType type) {
return NULL;
}
token->literal = mapping_result;
token->lexeme = mapping_result;
}