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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user