Fixed some functionality in symbol_table and added print_symbole_table t#29

This commit is contained in:
Meyer Simon
2025-02-21 09:32:06 -05:00
parent f2a0fbd1bc
commit 4468dbd02f
2 changed files with 84 additions and 26 deletions

View File

@ -30,7 +30,7 @@ typedef struct TableNode{
//this next value is an int for string types to tell you how far to traverse a buffer for the string
int StrLength;
}TableNode;
typedef struct SymbolTable{
TableNode* entries;
struct SymbolTable* Parent_Scope;
@ -40,7 +40,7 @@ typedef struct SymbolTable{
}SymbolTable;
*/
SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable));
table->Line_Number = Line;
@ -66,31 +66,27 @@ SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
}
return table;
}
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value, int StringLength){
if(table->entries == NULL){
TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode));
newEntry->theType = typeOf;
newEntry->theName = id;
newEntry->value = value;
newEntry->StrLength = StringLength;
return newEntry;
} else{
TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode));
newEntry->theType = typeOf;
newEntry->theName = id;
newEntry->value = value;
newEntry->StrLength = StringLength;
TableNode* oldEntry = table->entries;
table->entries = newEntry;
newEntry->next = oldEntry;
return newEntry;
}
}
//uncomment the below main function along with the headers above for a simple standalone test of table and entry creation
/*
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value, int StringLength){
TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode));
newEntry->theType = typeOf;
newEntry->theName = id;
newEntry->value = value;
newEntry->StrLength = StringLength;
if(table->entries == NULL){
table->entries = newEntry;
return newEntry;
} else{
TableNode* oldEntry = table->entries;
table->entries = newEntry;
newEntry->next = oldEntry;
return newEntry;
}
}
//uncomment the below main function along with the headers above for a simple standalone test of table and entry creation
/*
int main(){
char* String = "STRING";
char* X = "X";