continued working on table structure

This commit is contained in:
Partho Bhattacharya
2025-02-20 15:19:50 -05:00
parent 7836f6ecd0
commit 5f35308361

View File

@ -8,6 +8,8 @@ typedef struct ListOfTable{
struct SymbolTable* table; struct SymbolTable* table;
struct ListOfTable* prev; struct ListOfTable* prev;
struct ListOfTable* next; struct ListOfTable* next;
int Line_Number;
int Column_Number;
}ListOfTable; }ListOfTable;
typedef union Value{ typedef union Value{
@ -15,7 +17,6 @@ typedef union Value{
void* value_of_pointer; void* value_of_pointer;
bool* value_of_bool; bool* value_of_bool;
char* value_of_char; char* value_of_char;
int* size_of_char_array;
}Value; }Value;
typedef struct TableNode{ typedef struct TableNode{
@ -23,6 +24,8 @@ typedef struct TableNode{
string* theName; string* theName;
Value* value; Value* value;
struct TableNode* next; struct TableNode* next;
//this next value is an int for string types to tell you how far to traverse a buffer for the string
int StrLength;
}TableNode; }TableNode;
typedef struct SymbolTable{ typedef struct SymbolTable{
@ -31,18 +34,23 @@ typedef struct SymbolTable{
struct ListOfTable* Children_Scope; struct ListOfTable* Children_Scope;
}SymbolTable; }SymbolTable;
SymbolTable* CreateScope(SymbolTable* ParentScope){ SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable)); SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable));
table.Line_Number = Line;
table.Column_Number = Column;
table.Parent_Scope = ParentScope; table.Parent_Scope = ParentScope;
table.Children_Scope = NULL; table.Children_Scope = NULL;
table.entries = NULL; table.entries = NULL;
return table; return table;
} }
Entry* CreateEntry(SymbolTable* table, string typeOf, string id, Value value){ TableNode* CreateEntry(SymbolTable* table, string typeOf, string id, Value value, int StringLength){
if( if(table.entries == NULL){
TableNode* newEntry = (TableNode*)malloc(sizeof(SymbolTable));
newEntry.theType = typeOf;
newEntry.theName = id;
newEntry.StrLength = StringLength;
} else{