diff --git a/src/runner.c b/src/runner.c index f02e2cf..238abf1 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2,6 +2,8 @@ /* The Translators - Spring 2025 */ #include "runner.h" +extern TableNode* funprime; +extern TableNode* arrayprim; int main(int argc, char *argv[]) { if (argc == 1) { diff --git a/src/symbol_table.c b/src/symbol_table.c index c50eac8..7e8c339 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -8,6 +8,8 @@ #include char * typey = "type"; char * funy = "function"; +TableNode* funprime; +TableNode* arrayprim; typedef enum { //First 4 below are primitive types that are all encapsulated in primitive type @@ -81,18 +83,20 @@ primitive_info* CreatePrimitiveInfo(size){ return prim; } -string_info* CreateStringInfo(int length, char* loc){ +//probably don't need the below structure since can create from an array +/*string_info* CreateStringInfo(int length, char* loc){ string_info* stringy = (string_info*)malloc(sizeof(string_info)); stringy.length=length; char* location = loc; return stringy; } - -array_info* CreateArrayInfo(int dim, int* sizes, TableNode* type){ +*/ +array_info* CreateArrayInfo(int dim, /*int* sizes,*/ TableNode* type){ array_info* arr = (array_info*)malloc(sizeof(array_info)); arr.numofdimensions=dim; - arr.typeofarray=type; - int* dimensionsizes = loc; + arr->typeofarray=type; + //avoiding storing any types like below + //int* dimensionsizes = loc; return arr; } @@ -103,6 +107,7 @@ record_info* CreateRecordInfo(int length, TableNode* typesarray){ return reccy; } +//below function takes a bool to see if parameter should be decomposed or not function_declaration_info* CreateFunctionDeclarationInfo(int line, bool asorregular){ function_declaration_info* fundec = (function_declaration_info*)malloc(sizeof(function_declaration_info)); fundec.startlinenumber=line; @@ -158,19 +163,21 @@ SymbolTable* init(SymbolTable* start){ TableNode* chara = (TableNode*)malloc(sizeof(SymbolTable)); TableNode* stri = (TableNode*)malloc(sizeof(SymbolTable)); TableNode* boo = (TableNode*)malloc(sizeof(SymbolTable)); - TableNode* arr = (TableNode*)malloc(sizeof(SymbolTable)); + //TableNode* arr = (TableNode*)malloc(sizeof(SymbolTable)); start->entries = integ; integ->next = addr; addr->next = chara; chara->next = stri; stri->next = boo; - boo->next = arr; + //boo->next = arr; + boo->next = NULL; + integ->theName= "integer"; addr->theName= "address"; chara->theName= "character"; boo->theName= "Boolean"; stri->theName= "string"; - arr->theName= "array" + //arr->theName= "array" //root TableNode that all are pointing to but not in table TableNode* prime = (TableNode*)malloc(sizeof(SymbolTable)); @@ -178,19 +185,37 @@ SymbolTable* init(SymbolTable* start){ prime->theType=NULL; prime->additionalinfo = NULL; prime->next = NULL; - - TableNode* striprim = (TableNode*)malloc(sizeof(SymbolTable)); - prime->theName= "1->character"; + + //note sur exatly how to get array types to look right so using a dummy Table Node below and updating the print symbol table function to access the additional information to print for array types, similar to function types + TableNode* arrayprim = (TableNode*)malloc(sizeof(SymbolTable)); + prime->theName= "array"; prime->theType=NULL; prime->additionalinfo = NULL; prime->next = NULL; + //funprime = CreateEntry(NULL,NULL,strdup("function primitive"),NULL); + + //similar workaround to arrays above + TableNode* funprime = (TableNode*)malloc(sizeof(SymbolTable)); + prime->theName= "primitive function"; + prime->theType=NULL; + prime->additionalinfo = NULL; + prime->next = NULL; + integ->theType=prime; addr->theType=prime; chara->theType=prime; stri->theType=striprim; boo->theType=prime; - arr->theType=prime; + arr->theType=arrayprim; + + //filling in all the values for the additional info for initial types + integ->additionalinfo = CreatePrimitiveInfo(4); + addr->additionalinfo = CreatePrimitiveInfo(8); + chara->additionalinfo = CreatePrimitiveInfo(1); + stri->additionalinfo = CreateArrayInfo(1,chara); + boo->additionalinfo = CreatePrimitiveInfo(1); + //addr->additionalinfo = CreatePrimitiveInfo(8); start->Line_Number = 1; start->Column_Number = 1; @@ -304,6 +329,7 @@ void print_symbol_table(SymbolTable* table, FILE* file_ptr) { } for (; entrie != NULL; entrie = entrie->next) { if (parant_scope == 0) { + if(strcmp(entrie->theType->theName,"function primitive")|| strccmp(entrie->theType->theName," fprintf(file_ptr, "%-17s: %06d : : %-21s: %-28s\n", entrie->theName, current_scope, entrie->theType->theName, "Extra annotation"); diff --git a/src/symbol_table.h b/src/symbol_table.h index 497cf3f..42b0304 100644 --- a/src/symbol_table.h +++ b/src/symbol_table.h @@ -7,15 +7,20 @@ typedef struct{ int size; }primitive_info; +/*This structure can be subsumed into the structure below (1-d array of chars) typedef struct{ - int length; - char* location; + //shouldn't need to store any values since would be compiled at runtime + //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; - int* sizesofdimensions; + //shouldn't need to store any values (like sizes of dimenions or the location + //int* sizesofdimensions; + //do have to store type of array TableNode* typeofarray; }array_info; @@ -35,12 +40,12 @@ typedef struct{ }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; + primitive_info* PrimAdInfo; + array_info* ArrayAdInfo; + record_info* RecAdInfo; + //string_info* StringAdInfo; + func_dec_info* FunDecAdInfo; + func_type_info* FunTypeAdInfo; }AdInfo; typedef struct ListOfTable {