44 lines
1.0 KiB
C
44 lines
1.0 KiB
C
#ifndef SYMBOLSTABLE_H
|
|
#define SYMBOLSTABLE_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include "opcodes.h"
|
|
#include "token.h"
|
|
|
|
#define SYMBOLSTABLE_DEFAULT_CAPACITY 128
|
|
|
|
typedef struct __token_node {
|
|
Token* Token;
|
|
struct __token_node* Left;
|
|
struct __token_node* Right;
|
|
} TokenNode;
|
|
|
|
typedef struct _symbol {
|
|
char* Name;
|
|
int Address;
|
|
int Length;
|
|
Token* Token;
|
|
TokenNode* ValueExpression;
|
|
} Symbol;
|
|
|
|
typedef struct {
|
|
Symbol** Symbols;
|
|
int Size;
|
|
int Capacity;
|
|
} SymbolTable;
|
|
|
|
SymbolTable* CreateSymbolTable(void);
|
|
TokenNode* CreateTokenNode(Token* token);
|
|
int TryGetSymbol(char* name, SymbolTable* table, Symbol** outSymbol);
|
|
Symbol* AddSymbolToTable(char* name, int address, SymbolTable* table);
|
|
void FreeSymbolTable(SymbolTable* table);
|
|
void FreeSymbol(Symbol* symbol);
|
|
int SymbolResolved(Symbol* symbol);
|
|
int TryGetSymbolValue(const Symbol* symbol, const SymbolTable* table, unsigned short** value);
|
|
|
|
#endif |