From e0ab5540da8dd3f0b2cb0d15ee30581b82c47ec3 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 21 Feb 2025 12:52:24 -0500 Subject: [PATCH] edited symbol table node structure to remove strlength and value as they are not needed --- symbol_table.c | 54 ++++++------------------------------------------- symbol_table.h | 12 +---------- test | Bin 0 -> 16088 bytes 3 files changed, 7 insertions(+), 59 deletions(-) create mode 100755 test diff --git a/symbol_table.c b/symbol_table.c index 0e4c3d0..9cbdf90 100644 --- a/symbol_table.c +++ b/symbol_table.c @@ -1,45 +1,8 @@ //Defining a symbol table //Using a Linked List Structure. Head of linked List points to parent scope (if one exists) -//Tail of Linked List points to a Linked List of all the child scopes -//T -//*#include "symbol_table.h" -/* -#include -#include -#include +//Tail of Linked List points to a List of child scopes -typedef struct ListOfTable{ - struct SymbolTable* table; - //struct ListOfTable* prev; - struct ListOfTable* next; - -}ListOfTable; - -typedef union Value{ - int* value_of_int; - void* value_of_pointer; - bool* value_of_bool; - char* value_of_char; - }Value; - -typedef struct TableNode{ - char* theType; - char* theName; - Value* value; - 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; - -typedef struct SymbolTable{ - TableNode* entries; - struct SymbolTable* Parent_Scope; - struct ListOfTable* Children_Scope; - int Line_Number; - int Column_Number; - }SymbolTable; - -*/ +#include "symbol_table.h" SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){ SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable)); @@ -68,12 +31,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; @@ -86,16 +47,13 @@ TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value, } //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 type of the first entry is %s\n",First_Entry->theType); return 0; } -*/ diff --git a/symbol_table.h b/symbol_table.h index 1e002d0..d510a3b 100644 --- a/symbol_table.h +++ b/symbol_table.h @@ -9,20 +9,10 @@ typedef struct ListOfTable{ }ListOfTable; -typedef union Value{ - int* value_of_int; - void* value_of_pointer; - bool* value_of_bool; - char* value_of_char; - }Value; - typedef struct TableNode{ char* theType; char* theName; - Value* value; 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; typedef struct SymbolTable{ @@ -34,5 +24,5 @@ typedef struct SymbolTable{ }SymbolTable; -TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value, int StringLength); +TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id); SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column); diff --git a/test b/test new file mode 100755 index 0000000000000000000000000000000000000000..4941bf240c8f2f1ec1cf50ca112b79be646ae11c GIT binary patch literal 16088 zcmeHOZ)_Y#6(2iI>d+*RbH+whpg^sB8Z9&Wm?6-bGFe+m>sY=3lyD7HsX}iyVkJ}}BucpX%3%r!MX2I_5N;tU zm=DsU9EVWRm)o-ljAH4}GW`J=pa}KjD3tL=tybeZE9qg*%OF$15lgrU#!WCz=nS_f zRPsqVp=&$$BS@Q|qarkj8)RINwi}odN^MX%blyw6pZ2;L=ULi~3Q}oDsI+${a6GgI zc$H5X=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