Reworked the tokens to include a broad class to make parameter matching a bit easier, and removed the hexadecimal distinction.
This commit is contained in:
+18
@@ -1,5 +1,7 @@
|
||||
#include "../includes/token.h"
|
||||
|
||||
TokenClass GetTokenClass(TokenType);
|
||||
|
||||
Token* CreateToken(char* lexeme, void* value, int lineNumber, TokenType type) {
|
||||
Token* token = calloc(1, sizeof(Token));
|
||||
|
||||
@@ -12,10 +14,26 @@ Token* CreateToken(char* lexeme, void* value, int lineNumber, TokenType type) {
|
||||
token->line = lineNumber;
|
||||
token->lexeme = lexeme;
|
||||
token->value = value;
|
||||
token->token_class = GetTokenClass(type);
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
TokenClass GetTokenClass(TokenType type) {
|
||||
if (type >= R1 && type <= R8) return Reg;
|
||||
if (type >= COPY && type <= OUT) return Opcode;
|
||||
|
||||
switch(type) {
|
||||
case STRING:
|
||||
case IDENTIFIER:
|
||||
case LABEL:
|
||||
case NUMBER:
|
||||
return Immediate16;
|
||||
default:
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
void FreeToken(Token* token) {
|
||||
if (!token) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user