Modified how registers and opcodes are represented. This commit is a bit buggy but doesn't crash and burn at least. I just wanted the new structs push out before making a bigger mess of things as I try to organize this all.
This commit is contained in:
+21
-8
@@ -2,6 +2,7 @@
|
||||
#include "../includes/opcodes.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
Token* CreateToken(TokenType, char*);
|
||||
Token* GetNextToken(char *);
|
||||
@@ -27,14 +28,17 @@ List* GetTokensFromLine(char* line) {
|
||||
Token* GetNextToken(char *string) {
|
||||
char* string_token = GetToken(string);
|
||||
int base = 0;
|
||||
TokenType type;
|
||||
|
||||
while (strlen(string_token) != 0) {
|
||||
|
||||
if (string_token[0] == '.') return CreateToken(TK_Directive, string_token);
|
||||
if (strcmp(string_token, ".db") == 0) {
|
||||
return CreateToken(DB, string_token);
|
||||
}
|
||||
|
||||
if (TokenIsNumeric(string_token, &base)) {
|
||||
if (base == 10) return CreateToken(TK_Number, string_token);
|
||||
if (base == 16) return CreateToken(TK_Hex, string_token);
|
||||
if (base == 10) return CreateToken(NUMBER, string_token);
|
||||
if (base == 16) return CreateToken(HEX, string_token);
|
||||
}
|
||||
|
||||
char* next = PeekNextToken();
|
||||
@@ -43,17 +47,26 @@ Token* GetNextToken(char *string) {
|
||||
if (strcmp(":", next) == 0) {
|
||||
free(next);
|
||||
free(GetToken(NULL));
|
||||
return CreateToken(TK_Symbol, string_token);
|
||||
return CreateToken(IDENTIFIER, string_token);
|
||||
}
|
||||
|
||||
free(next);
|
||||
}
|
||||
|
||||
if (IsOpcode(string_token)) return CreateToken(TK_Opcode, string_token);
|
||||
if (IsRegister(string_token)) return CreateToken(TK_Register, string_token);
|
||||
if (strcmp(",", string_token) == 0) return CreateToken(TK_Comma, string_token);
|
||||
if (IsOpcode(string_token, &type)) {
|
||||
return CreateToken(type, string_token);
|
||||
}
|
||||
|
||||
return CreateToken(TK_String, string_token);
|
||||
if (IsRegister(string_token, &type)) {
|
||||
return CreateToken(type, string_token);
|
||||
}
|
||||
|
||||
// if (op) return CreateToken(op->op, op->lexeme);
|
||||
// if (reg) return CreateToken(reg->type, reg->lexeme);
|
||||
|
||||
if (strcmp(",", string_token) == 0) return CreateToken(COMMA, string_token);
|
||||
|
||||
return CreateToken(IDENTIFIER, string_token);
|
||||
}
|
||||
|
||||
free(string_token);
|
||||
|
||||
Reference in New Issue
Block a user