it looks like this should work. t#29

This commit is contained in:
Meyer Simon
2025-02-21 14:30:14 -05:00
parent ad5da96857
commit fcb66c125d
7 changed files with 136 additions and 34 deletions

View File

@ -68,12 +68,10 @@ SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
}
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value, int StringLength){
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id){
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;
@ -84,18 +82,35 @@ TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value,
return newEntry;
}
}
TableNode * table_lookup(SymbolTable * table, char * x){
TableNode * entrie = table->entries;
for(; entrie != NULL; entrie = entrie->next){
if (!strcmp(entrie->theName, x)){
return entrie;
}
}
return NULL;
}
TableNode * look_up(SymbolTable * table, char * x){
if(table == NULL){
return NULL;
}
TableNode * ret = table_lookup(table, x);
if (ret != NULL){
return ret;
}
return look_up(table->Parent_Scope, x);
}
//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";
Value* ofX = (Value*)malloc(sizeof(Value));
ofX->value_of_char = X;
SymbolTable* Second = CreateScope(NULL, 2,2);
printf("Line number is %d, Column number of scope is %d\n",Second->Line_Number,Second->Column_Number);
TableNode* First_Entry = CreateEntry(Second,String,X,ofX,-1);
printf("The value of the first entry is %s\n",First_Entry->value->value_of_char);
TableNode* First_Entry = CreateEntry(Second,String,X);
printf("The value of the first entry is %s\n",First_Entry->theType);
return 0;
}
*/