diff --git a/src/grammar.y b/src/grammar.y index fcb06b8..b7438bd 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -36,7 +36,7 @@ char * words; } - +%type idlist %type assignable %type expression %type constant @@ -121,27 +121,39 @@ prototype: L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; definition: -TYPE ID COLON {tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0))); +TYPE ID COLON { + printf("Currently see a record definition for %s\n", $2); + tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0))); if (table_lookup(getAncestor(cur), $2) == NULL) { printf("rec not found \n"); } }dblock { setRecSize(table_lookup(getParent(cur), $2), getRecSize(cur)); cur = getParent(cur);} - | TYPE ID COLON C_INTEGER ARROW id_or_types { CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));} + | TYPE ID COLON C_INTEGER ARROW id_or_types + {printf("Currently see a array definition of name %s,storing type %s, of dimensions %d\n", + $2, $6, $4); + CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));} | function_declaration | TYPE ID COLON id_or_types ARROW id_or_types { + printf("Currently see a function type definition of name %s,parameter type %s, of return type %s\n", + $2, $4, $6); CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$6))); } | ID { TableNode *node = table_lookup(getAncestor(cur), $1); - if (node == NULL || getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) { + if (node == NULL) { printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); - } else { + }else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){ + printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); + } + else { setStartLine(node, @1.first_line); setAsKeyword(node, false); } cur = CreateScope(cur, 0, 0); } L_PAREN ID { + printf("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s\n", + $1,$4); CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1)))), $4, NULL); }R_PAREN ASSIGN sblock | ID { @@ -149,23 +161,29 @@ TYPE ID COLON {tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo if (node == NULL) { printf("null check\n"); } - if (node == NULL || getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) { + if (node == NULL) { printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); - } else { + }else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){ + printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); + } + else { setStartLine(node, @1.first_line); setAsKeyword(node, false); } cur = CreateScope(cur, 0, 0); }AS L_PAREN { TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1)))); - if (parameter == NULL || getAdInfoType(parameter) != TYPE_RECORD) { + if (parameter == NULL) { printf("function defined with as, but parameter is not a record at line %d, column %d\n", @1.first_line, @1.first_column); - } else { + }else if(getAdInfoType(parameter) != TYPE_RECORD){ + printf("function defined with as, but parameter is not a record at line %d, column %d\n", @1.first_line, @1.first_column); + }else { for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){ CreateEntry(cur, entry, NULL, NULL); } } - } idlist R_PAREN ASSIGN sblock + } idlist {printf("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d\n", + $1,$6);} R_PAREN ASSIGN sblock ; @@ -185,7 +203,7 @@ idlist: printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column); } addName(entry, $1); - } COMMA idlist + } COMMA idlist {$$ = $3 + 1;} | ID { TableNode *entry = getFirstEntry(cur); @@ -196,6 +214,7 @@ idlist: printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column); } addName(entry, $1); + $$ = 1; } ; diff --git a/src/symbol_table.c b/src/symbol_table.c index 7f8849b..e8e1868 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -19,6 +19,7 @@ TableNode *boo; TableNode *recprime; TableNode *funtypeprime; TableNode *undefined; +//AdInfo *Undefined_function_type_info; typedef enum { // First 4 below are primitive types that are all encapsulated in @@ -133,6 +134,10 @@ int getPrimSize(TableNode *definition) { // type stored in the array per professor, the actual size of the array is // calculated at runtime so bounds checking only needs to be done then AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) { + if(type == NULL || type == undefined){ + printf("passed a NULL or undefined type reference to CreateArrayInfo. Invalid.\n"); + return NULL; + } AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); info->ArrayAdInfo = (array_info *)malloc(sizeof(array_info)); info->ArrayAdInfo->numofdimensions = dim; @@ -144,7 +149,7 @@ AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) { // This gets the number of dimensions from array info int getNumArrDim(TableNode *definition) { if (definition == NULL|| definition == undefined){ - printf("passed an NULL entry to getNumArrDim function. Invalid.\n"); + printf("passed an NULL or undefined entry to getNumArrDim function. Invalid.\n"); return -1; } if (strcmp(getType(definition), "array") != 0) { @@ -156,6 +161,10 @@ int getNumArrDim(TableNode *definition) { // This gets the type stored in an array from arrtype. It returns a reference to // the entry of that type TableNode *getArrType(TableNode *definition) { + if(definition == NULL|| definition == undefined){ + printf("passed an NULL or undefined entry to getArrType function. Invalid.\n"); + return NULL; + } if (strcmp(getType(definition), "array") != 0) { printf("not checking the type of an array -- invalid op\n"); return undefined; @@ -179,6 +188,10 @@ AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope) { // Perhaps this may not be needed since we need to iterate over all elements // anyways. int getRecLength(TableNode *definition) { + if (definition == NULL|| definition == undefined){ + printf("passed an NULL or undefined entry to getRecLength function. Invalid.\n"); + return -1; + } if (strcmp(getType(definition), "record") != 0) { printf("not checking the length of an record -- invalid op\n"); return 0; @@ -187,6 +200,10 @@ int getRecLength(TableNode *definition) { } // This gets the array. Needs to up be updated to get the scope instead SymbolTable *getRecList(TableNode *definition) { + if (definition == NULL|| definition == undefined){ + printf("passed an NULL or undefined entry to getRecList function. Invalid.\n"); + return NULL; + } if (strcmp(getType(definition), "record") != 0) { printf("not checking the list of types of a record -- invalid " "op\n"); @@ -205,13 +222,20 @@ TableNode* setRecSize(TableNode* tn, int n){ } int getRecSize(SymbolTable* tn){ + if(tn == NULL){ + printf("passed in NULL SymbolTable for getRecSize. Invalid\n"); + return -1; + } int s = 0; TableNode* cur = getFirstEntry(tn); + if (cur != NULL){ while(getNextEntry(cur) != NULL){ s++; cur = getNextEntry(cur); } return s; + } +return -1; } // below function takes a bool to see if parameter should be decomposed or not @@ -230,6 +254,10 @@ AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular) { // gets the line at which the function was first defined. (Can be used to print // out in table if needed) int getStartLine(TableNode *definition) { + if (definition == NULL|| definition == undefined){ + printf("passed an NULL or undefined entry to getStartLine function. Invalid.\n"); + return -1; + } if (strcmp(getType(definition), "primitive function") != 0) { printf("not checking the start line of a function -- invalid " "op\n"); @@ -249,6 +277,10 @@ TableNode* setStartLine(TableNode* tn, int start){ // checks if "as" keyword was used for function definition. Either 0 or 1 for // not used or used. bool getAsKeyword(TableNode *definition) { + if (definition == NULL|| definition == undefined){ + printf("passed an NULL or undefined entry to getAsKeyword function. Invalid.\n"); + return false; + } if (strcmp(getType(definition), "primitive function") != 0) { printf("not checking if a function is called with as or not -- " "invalid op\n"); @@ -268,6 +300,14 @@ TableNode* setAsKeyword(TableNode* tn, bool as){ // stores the type of a function (parameter type and return type) AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) { + if(parameter == NULL||parameter == undefined){ + printf("passed a NULL or undefined parameter to CreateFunctionTypeInfo. Invalid.\n"); + return NULL; + } + if(returntype == NULL||returntype == undefined){ + printf("passed a NULL or undefined return type to CreateFunctionTypeInfo. Invalid.\n"); + return NULL; + } AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); info->FunTypeAdInfo = (function_type_info *)malloc(sizeof(function_type_info)); @@ -277,6 +317,10 @@ AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) { } // returns parameter type of a function TableNode *getParameter(TableNode *definition) { + if (definition == NULL|| definition == undefined){ + printf("passed an NULL or undefined entry to getParameter function. Invalid.\n"); + return undefined; + } if (strcmp(getType(definition), "primitive function type") != 0) { printf( "not checking the parameter of a function -- invalid op\n"); @@ -286,6 +330,10 @@ TableNode *getParameter(TableNode *definition) { } // returns return type of a function TableNode *getReturn(TableNode *definition) { + if (definition == NULL|| definition == undefined){ + printf("passed an NULL or undefined entry to getReturn function. Invalid.\n"); + return NULL; + } if (strcmp(getType(definition), "primitive function type") != 0) { printf("not checking the return of a function -- invalid op\n"); return undefined; @@ -331,11 +379,11 @@ SymbolTable *init(SymbolTable *start) { "Cannot initialize a scope that is not the parent scope\n"); return NULL; } - integ = (TableNode *)malloc(sizeof(TableNode)); - addr = (TableNode *)malloc(sizeof(TableNode)); - chara = (TableNode *)malloc(sizeof(TableNode)); - stri = (TableNode *)malloc(sizeof(TableNode)); - boo = (TableNode *)malloc(sizeof(TableNode)); + integ = (TableNode *)calloc(1,sizeof(TableNode)); + addr = (TableNode *)calloc(1,sizeof(TableNode)); + chara = (TableNode *)calloc(1,sizeof(TableNode)); + stri = (TableNode *)calloc(1,sizeof(TableNode)); + boo = (TableNode *)calloc(1,sizeof(TableNode)); // TableNode* arr = (TableNode*)malloc(sizeof(SymbolTable)); start->entries = integ; integ->next = addr; @@ -402,6 +450,8 @@ SymbolTable *init(SymbolTable *start) { undefined->additionalinfo = NULL; undefined->next = NULL; + //Undefined_function_type_info = CreateFunctionTypeInfo(undefined, undefined); + integ->theType = prime; addr->theType = prime; chara->theType = prime; @@ -465,31 +515,31 @@ int getAdInfoType(TableNode* tn){ printf("Entry being passed in has a null or undefined reference for theType. Invalid.\n"); return -1; } - if(strcmp(getType(tn),getName(integ))==0){ + if(strcmp(getName(tn),getName(integ))==0){ return TYPE_PRIMITIVE; } - if(strcmp(getType(tn),getName(addr))==0){ + if(strcmp(getName(tn),getName(addr))==0){ return TYPE_PRIMITIVE; } - if(strcmp(getType(tn),getName(chara))==0){ + if(strcmp(getName(tn),getName(chara))==0){ return TYPE_PRIMITIVE; } - if(strcmp(getType(tn),getName(stri))==0){ + if(strcmp(getName(tn),getName(stri))==0){ return TYPE_ARRAY; } - if(strcmp(getType(tn),getName(boo))==0){ + if(strcmp(getName(tn),getName(boo))==0){ return TYPE_PRIMITIVE; } - if(strcmp(getType(tn),getName(recprime))==0){ + if(strcmp(getName(tn),getName(recprime))==0){ return TYPE_RECORD; } - if(strcmp(getType(tn),getName(funtypeprime))==0){ + if(strcmp(getName(tn),getName(funtypeprime))==0){ return TYPE_FUNCTION_TYPE; } - if(strcmp(getType(tn),getName(arrayprim))==0){ + if(strcmp(getName(tn),getName(arrayprim))==0){ return TYPE_ARRAY; } - if(strcmp(getType(tn),getName(undefined))==0){ + if(strcmp(getName(tn),getName(undefined))==0){ return TYPE_UNDEFINED; } else{ @@ -497,13 +547,13 @@ int getAdInfoType(TableNode* tn){ } } -TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id, - AdInfo *ad) { +TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id, AdInfo *ad) { if (table == NULL) { printf("Null reference to table"); return undefined; } + /* TableNode* topDef = (table_lookup(getAncestor(table),typeOf)); if(topDef == NULL){ @@ -553,8 +603,18 @@ char *getName(TableNode *tn) { return tn->theName; } -int getLine(SymbolTable *st) { return st->Line_Number; } -int getColumn(SymbolTable *st) { return st->Column_Number; } +int getLine(SymbolTable *st) { + if(st == NULL){ + printf("passed a NULL symbol table to getLine function. Invalid.\n"); + return -1; + } + return st->Line_Number; } +int getColumn(SymbolTable *st) { + if(st == NULL){ + printf("passed a NULL symbol table to getColumn function. Invalid.\n"); + return -1; + } + return st->Column_Number; } TableNode* addName(TableNode *tn, char* str){ if(tn == NULL||tn==undefined){ printf("passed a Null or undefined table node to the addName function. Invalid./n"); @@ -626,6 +686,10 @@ names\n"); return NULL; */ //only check table that is given TableNode *table_lookup(SymbolTable *table, char *x) { + if(table == NULL) { + printf("passed in empty scope. error.\n"); + return undefined; + } TableNode *entrie = table->entries; for (; entrie != NULL; entrie = entrie->next) { if (!strcmp(entrie->theName, x)) { @@ -648,8 +712,9 @@ TableNode *look_up(SymbolTable *table, char *x) { ,x,getLine(table),getColumn(table)); return look_up(table->Parent_Scope, x); } - +/* void print_symbol_table(SymbolTable *table, FILE *file_ptr) { + if (table->Parent_Scope == NULL) { fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", "SCOPE", "PARENT", "TYPE", "Extra annotation"); @@ -674,7 +739,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } for (; entrie != NULL; entrie = entrie->next) { if (parant_scope == 0) { - /*have to update*/ if (strcmp(entrie->theType->theName, + /*have to update if (strcmp(entrie->theType->theName, "function primitive") || strcmp(entrie->theType->theName, "array")) { @@ -700,124 +765,139 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { "--------------:-------" "----------------------\n"); } -} -// void print_symbol_table(SymbolTable *table, FILE *file_ptr) { +}*/ +void print_symbol_table(SymbolTable *table, FILE *file_ptr) { -// if (table->Parent_Scope == NULL) { -// fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", -// "SCOPE", "PARENT", "TYPE", "Extra annotation"); -// } -// TableNode *entrie = table->entries; -// fprintf(file_ptr, "-----------------:--------:--------:----------------" -// "------:---------" -// "--------------------\n"); -// int parant_scope = 0; -// int current_scope = 0; -// if (table->Parent_Scope != NULL) { -// parant_scope = table->Parent_Scope->Line_Number * 1000 + -// table->Parent_Scope->Column_Number; -// current_scope = -// table->Line_Number * 1000 + table->Column_Number; -// } else { -// current_scope = 1001; -// } -// if (entrie == NULL) { -// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "", -// current_scope, parant_scope, "", "Empty Scope"); -// } -// for (;entrie != NULL; entrie = entrie->next) { -// if (getAdInfoType(entrie) == TYPE_ARRAY){ -// if (parant_scope == 0) { + if (table->Parent_Scope == NULL) { + fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", + "SCOPE", "PARENT", "TYPE", "Extra annotation"); + } + TableNode *entrie = table->entries; + fprintf(file_ptr, "-----------------:--------:--------:----------------" + "------:---------" + "--------------------\n"); + int parant_scope = 0; + int current_scope = 0; + if (table->Parent_Scope != NULL) { + parant_scope = table->Parent_Scope->Line_Number * 1000 + + table->Parent_Scope->Column_Number; + current_scope = + table->Line_Number * 1000 + table->Column_Number; + } else { + current_scope = 1001; + } + if (entrie == NULL) { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "", + current_scope, parant_scope, "", "Empty Scope"); + } + for (;entrie != NULL; entrie = entrie->next) { + if (getAdInfoType(entrie) == TYPE_ARRAY){ + if (parant_scope == 0) { -// fprintf(file_ptr, -// "%-17s: %06d : : %-21d -> %-21s: %-28s\n", -// entrie->theName, current_scope, -// entrie->additionalinfo->ArrayAdInfo->numofdimensions, -// entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, -// "Type of Array"); -// } else { -// fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n", -// entrie->theName, current_scope, parant_scope, -// entrie->additionalinfo->ArrayAdInfo->numofdimensions, -// entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, -// "Type of Array"); -// } -// } -// if (getAdInfoType(entrie) == TYPE_RECORD){ -// if (parant_scope == 0) { + fprintf(file_ptr, + "%-17s: %06d : : %-21d -> %-21s: %-28s\n", + entrie->theName, current_scope, + entrie->additionalinfo->ArrayAdInfo->numofdimensions, + entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, + "Type of Array"); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n", + entrie->theName, current_scope, parant_scope, + entrie->additionalinfo->ArrayAdInfo->numofdimensions, + entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, + "Type of Array"); + } + } + if (getAdInfoType(entrie) == TYPE_RECORD){ + if (parant_scope == 0) { -// fprintf(file_ptr, -// "%-17s: %06d : :%-21s: elements-%-28d\n", -// entrie->theName, current_scope, -// "record", -// entrie->additionalinfo->RecAdInfo->numofelements); -// } else { -// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: elements-%-28d\n", -// entrie->theName, current_scope, parant_scope, -// "record", -// entrie->additionalinfo->RecAdInfo->numofelements); -// } -// } -// if (getAdInfoType(entrie) == TYPE_PRIMITIVE){ -// if (parant_scope == 0) { + fprintf(file_ptr, + "%-17s: %06d : :%-21s: elements-%-28d\n", + entrie->theName, current_scope, + "record", + entrie->additionalinfo->RecAdInfo->numofelements); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: elements-%-28d\n", + entrie->theName, current_scope, parant_scope, + "record", + entrie->additionalinfo->RecAdInfo->numofelements); + } + } + if (getAdInfoType(entrie) == TYPE_PRIMITIVE){ + if (parant_scope == 0) { -// fprintf(file_ptr, -// "%-17s: %06d : :%-21s: size-%-28d bytes\n", -// entrie->theName, current_scope, -// "Primitive", -// entrie->additionalinfo->PrimAdInfo->size); -// } else { -// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: size-%-28d bytes\n", -// entrie->theName, current_scope, parant_scope, -// "Primitive", -// entrie->additionalinfo->PrimAdInfo->size); -// } -// } -// if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE){ -// if (parant_scope == 0) { + fprintf(file_ptr, + "%-17s: %06d : :%-21s: size-%-28d bytes\n", + entrie->theName, current_scope, + "Primitive", + entrie->additionalinfo->PrimAdInfo->size); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: size-%-28d bytes\n", + entrie->theName, current_scope, parant_scope, + "Primitive", + entrie->additionalinfo->PrimAdInfo->size); + } + } + if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE){ + if (parant_scope == 0) { -// fprintf(file_ptr, -// "%-17s: %06d : : %-21s -> %-21s: %-28s\n", -// entrie->theName, current_scope, -// entrie->additionalinfo->FunTypeAdInfo->parameter->theName, -// entrie->additionalinfo->FunTypeAdInfo->returntype->theName, -// "Type of Function"); -// } else { -// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s -> %-21s: %-28s\n", -// entrie->theName, current_scope, parant_scope, -// entrie->additionalinfo->FunTypeAdInfo->parameter->theName, -// entrie->additionalinfo->FunTypeAdInfo->returntype->theName, -// "Type of Function"); -// } -// } -// if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION){ -// if (parant_scope == 0) { + fprintf(file_ptr, + "%-17s: %06d : : %-21s -> %-21s: %-28s\n", + entrie->theName, current_scope, + entrie->additionalinfo->FunTypeAdInfo->parameter->theName, + entrie->additionalinfo->FunTypeAdInfo->returntype->theName, + "Type of Function"); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s -> %-21s: %-28s\n", + entrie->theName, current_scope, parant_scope, + entrie->additionalinfo->FunTypeAdInfo->parameter->theName, + entrie->additionalinfo->FunTypeAdInfo->returntype->theName, + "Type of Function"); + } + } + if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION){ + if (parant_scope == 0) { -// fprintf(file_ptr, -// "%-17s: %06d : :%-21s: %-28s\n", -// entrie->theName, current_scope, -// getType(entrie), -// "Function"); -// } else { -// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", -// entrie->theName, current_scope, parant_scope, -// getType(entrie), -// "Function"); -// } -// } -// } -// if (table->Children_Scope != NULL) { -// ListOfTable *node = table->Children_Scope; -// for (; node != NULL; node = node->next) { -// print_symbol_table(node->table, file_ptr); -// } -// } -// if (table->Parent_Scope == NULL) { -// fprintf(file_ptr, "-----------------:--------:--------:--------" -// "--------------:-------" -// "----------------------\n"); -// } -// } + fprintf(file_ptr, + "%-17s: %06d : :%-21s: %-28s\n", + entrie->theName, current_scope, + getType(entrie), + "Function"); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", + entrie->theName, current_scope, parant_scope, + getType(entrie), + "Function"); + } + } + if (getAdInfoType(entrie) == TYPE_UNDEFINED){ + if (parant_scope == 0) { + + fprintf(file_ptr, + "%-17s: %06d : :%-21s: %-28s\n", + entrie->theName, current_scope, + "undefined", + "undefined entry"); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", + entrie->theName, current_scope, parant_scope, + "undefined", + "undefined entry"); + } + } +} + if (table->Children_Scope != NULL) { + ListOfTable *node = table->Children_Scope; + for (; node != NULL; node = node->next) { + print_symbol_table(node->table, file_ptr); + } + } + if (table->Parent_Scope == NULL) { + fprintf(file_ptr, "-----------------:--------:--------:--------" + "--------------:-------" + "----------------------\n"); + } +} //get top most symbol table SymbolTable *getAncestor(SymbolTable *table) { if(table == NULL){ diff --git a/tests/sprint2/sp2_function_types.alpha b/tests/sprint2/sp2_function_types.alpha new file mode 100644 index 0000000..509de78 --- /dev/null +++ b/tests/sprint2/sp2_function_types.alpha @@ -0,0 +1,17 @@ +type Boolean2Boolean: Boolean -> Boolean +type integer2integer: integer -> integer +type character2integer: character -> integer +type Boolean2integer: Boolean -> integer +type string2integer: string -> integer +function integerXinteger2integer: integerXinteger (*-> integer +type integerXinteger2Boolean: integerXinteger -> Boolean +type characterXcharacter2Boolean: characterXcharacter -> Boolean +type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean +type integer2address: integer -> address +type address2integer: address -> integer +external function printInteger: integer2integer +external function printCharacter: character2integer +external function printBoolean: Boolean2integer +external function reserve: integer2address +external function release: address2integer +function entry: string2integer*) \ No newline at end of file