Massive refactoring to simplify this whole setup. The Token List will be modified in place and reused in the Parser to normalize the list and generate a symbols table. Normalizing the token list will make sure the syntax is valid and the symbols table will have the relative offsets and length of symbol values. At least this is all the plan but one step at a time.
This commit is contained in:
@@ -11,28 +11,11 @@
|
||||
|
||||
#define SYMBOLSTABLE_DEFAULT_CAPACITY 128
|
||||
|
||||
typedef enum {
|
||||
StringSymbol,
|
||||
NumericSymbol,
|
||||
InstructionPointerSymbol,
|
||||
UnresolvedSymbol
|
||||
} SymbolType;
|
||||
|
||||
typedef struct {
|
||||
char* String;
|
||||
int Terminated;
|
||||
u_int8_t TerminatingByte;
|
||||
} SymbolString;
|
||||
|
||||
typedef struct {
|
||||
char* Name;
|
||||
SymbolType Type;
|
||||
|
||||
union {
|
||||
SymbolString* String;
|
||||
int Number;
|
||||
Instruction* Instruction;
|
||||
} Value;
|
||||
int Address;
|
||||
int Resolved;
|
||||
int Length;
|
||||
} Symbol;
|
||||
|
||||
typedef struct {
|
||||
@@ -42,9 +25,8 @@ typedef struct {
|
||||
} SymbolTable;
|
||||
|
||||
SymbolTable* CreateSymbolTable(void);
|
||||
Symbol* TryGetSymbol(char* name, SymbolTable* table);
|
||||
Symbol* AddSymbolToTable(char* name, SymbolType type, SymbolTable* table);
|
||||
SymbolString* CreateSymbolString(char* string, int terminated);
|
||||
int TryGetSymbol(char* name, SymbolTable* table, Symbol** outSymbol);
|
||||
Symbol* AddSymbolToTable(char* name, int address, int resolved, SymbolTable* table);
|
||||
void FreeSymbolTable(SymbolTable* table);
|
||||
void FreeSymbol(Symbol* symbol);
|
||||
|
||||
|
||||
+3
-1
@@ -24,7 +24,9 @@ typedef enum {
|
||||
typedef enum {
|
||||
DB,
|
||||
Include,
|
||||
Byte
|
||||
Byte,
|
||||
Load,
|
||||
Store
|
||||
} Directive;
|
||||
|
||||
typedef enum {
|
||||
|
||||
Reference in New Issue
Block a user