finished base code for table setup. Still have to check grammar

This commit is contained in:
Partho Bhattacharya
2025-02-20 17:50:25 -05:00
parent 5f35308361
commit b21d7039a2

View File

@ -6,10 +6,9 @@
typedef struct ListOfTable{ 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{
@ -32,27 +31,55 @@ typedef struct SymbolTable{
TableNode* entries; TableNode* entries;
struct SymbolTable* Parent_Scope; struct SymbolTable* Parent_Scope;
struct ListOfTable* Children_Scope; struct ListOfTable* Children_Scope;
int Line_Number;
int Column_Number;
}SymbolTable; }SymbolTable;
SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){ 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->Line_Number = Line;
table.Column_Number = Column; 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;
if(ParentScope->Children_scope == NULL){
ListOfTable* newEntry = (ListOfTable*)malloc(sizeof(ListOfTable));
newEntry->next = NULL;
//newEntry->prev = NULL;
newEntry->table = table;
ParentScope->Children_scope = newEntry;
} else{
ListOfTable* newEntry = (ListOfTable*)malloc(sizeof(ListOfTable));
//newEntry->prev = NULL;
newEntry->table= table;
ListOfTable* oldEntry = ParentScope->Children_scope;
ParentScope->Children_scope = newEntry;
newEntry->next = oldEntry;
}
return table;
}
return table; return table;
} }
TableNode* CreateEntry(SymbolTable* table, string typeOf, string id, Value value, int StringLength){ TableNode* CreateEntry(SymbolTable* table, string typeOf, string id, Value value, int StringLength){
if(table.entries == NULL){ if(table->entries == NULL){
TableNode* newEntry = (TableNode*)malloc(sizeof(SymbolTable)); TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode));
newEntry.theType = typeOf; newEntry->theType = typeOf;
newEntry.theName = id; newEntry->theName = id;
newEntry.StrLength = StringLength; newEntry->StrLength = StringLength;
return newEntry;
} else{ } else{
TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode));
newEntry->theType = typeOf;
newEntry->theName = id;
newEntry->StrLength = StringLength;
TableNode* oldEntry = table->entries;
table->entries = newEntry;
newEntry->next = oldEntry;
return newEntry;
}
}