diff --git a/src/symbol_table.c b/src/symbol_table.c index 4369551..08de0de 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -8,6 +8,71 @@ #include char * typey = "type"; char * funy = "function"; + +typedef enum { + //First 4 below are primitive types that are all encapsulated in primitive type + //TYPE_INTEGER, + //TYPE_CHARACTER, + //TYPE_BOOLEAN, + //TYPE_ADDRESS, + //Type String is an array of char enclosed in double quotes per lexer + TYPE_STRING, + //Array can be multidimensional. Information should be stored here + TYPE_ARRAY, + //Record is user defined types + TYPE_RECORD, + //Declaring what type a particular function is without as + TYPE_FUNCTION_DECLARATION, + //Declaring what type a particular function is with as + //TYPE_AS_FUNCTION_DECLARATION, + //Declaring what type a function is (what the parameters and output are) + TYPE_FUNCTION_TYPE, + //The Type being pointed to by the first 4 above that only stores the size + TYPE_PRIMITIVE + +} types; + +/* put in symbol_table.h +typedef struct{ + int size; +}primitive_info; + +typedef struct{ + int length; + char* location; +}string_info; + +typedef struct{ + int numofdimensions; + //the above value tells you how long the below array is. For example if num of dimensions is 5, I can store 1,3,2,5,9 to define a multidimensional array of that size + int* arr; +}array_info; + +typedef struct{ + //similar to above we define a record to hold the number of elements and an array of tablenodes (types) that it contains in the order specified by the user + int numofelements; + TableNode* listoftypes; +}record_info; + +typedef struct{ + int startlinenumber; + bool regularoras; +}function_declaration_info; + +typedef struct{ + TableNode* parameter; + TableNode* returntype; +}function_type_info; + +typedef union { + PrimAdInfo* primitive_info; + ArrayAdInfo* array_info; + RecAdInfo* record_info; + StringAdInfo* string_info; + FunDecAdInfo* func_dec_info; + FunTypeAdInfo* func_type_info; + }AdInfo; +*/ SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column) { SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable)); table->Line_Number = Line; @@ -35,10 +100,22 @@ SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column) { } //create entry just for things below top level scope +SymbolTable* init(SymbolTable* start){ + if(start->Parent_Scope == NULL){ + printf("Cannot initialize a scope that is not the parent scope\n"); + return NULL; + } + TableNode* table1 = (TableNode*)malloc(sizeof(SymbolTable)); + table->Line_Number = Line; + table->Column_Number = Column; + table->Parent_Scope = ParentScope; + table->Children_Scope = NULL; + table->entries = NULL; + TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id) { -if(table ==NULL /*|| table->Parent_Scope == NULL*/){ - printf("Null reference to table given for create entry or given top level scope which is invalid\n"); +if(table ==NULL){ + printf("Null reference to table"); return NULL; } /*TableNode* topDef = (table_lookup(getAncestor(table),typeOf)); diff --git a/src/symbol_table.h b/src/symbol_table.h index 03028ad..46caa02 100644 --- a/src/symbol_table.h +++ b/src/symbol_table.h @@ -3,6 +3,44 @@ #include #include +typedef struct{ + int size; +}primitive_info; + +typedef struct{ + int length; + char* location; +}string_info; + +typedef struct{ + int numofdimensions; + //the above value tells you how long the below array is. For example if num of dimensions is 5, I can store 1,3,2,5,9 to define > int* arr; +}array_info; + +typedef struct{ + //similar to above we define a record to hold the number of elements and an array of tablenodes (types) that it contains in the > int numofelements; + TableNode* listoftypes; +}record_info; + +typedef struct{ + int startlinenumber; + bool regularoras; +}function_declaration_info; + +typedef struct{ + TableNode* parameter; + TableNode* returntype; +}function_type_info; + +typedef union { + PrimAdInfo* primitive_info; + ArrayAdInfo* array_info; + RecAdInfo* record_info; + StringAdInfo* string_info; + FunDecAdInfo* func_dec_info; + FunTypeAdInfo* func_type_info; + }AdInfo; + typedef struct ListOfTable { struct SymbolTable* table; // struct ListOfTable* prev; @@ -10,8 +48,10 @@ typedef struct ListOfTable { } ListOfTable; typedef struct TableNode { - char* theType; + //reference to the type entry that this is + TableNode* theType; char* theName; + AdInfo* additionalinfo; struct TableNode* next; } TableNode;