fixed most things in the symbol table structure. Seeing core dumps and have to fix the print symbol table function
This commit is contained in:
@ -27,23 +27,23 @@ typedef enum {
|
||||
// TYPE_BOOLEAN,
|
||||
// TYPE_ADDRESS,
|
||||
// Type String is an array of char enclosed in double quotes per lexer
|
||||
TYPE_STRING,
|
||||
TYPE_STRING = 1,
|
||||
// Array can be multidimensional. Information should be stored here
|
||||
TYPE_ARRAY,
|
||||
TYPE_ARRAY = 2,
|
||||
// Record is user defined types
|
||||
TYPE_RECORD,
|
||||
TYPE_RECORD = 3,
|
||||
// Declaring what type a particular function is without as
|
||||
TYPE_FUNCTION_DECLARATION,
|
||||
TYPE_FUNCTION_DECLARATION = 4,
|
||||
// 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,
|
||||
TYPE_FUNCTION_TYPE = 5,
|
||||
// The Type being pointed to by the first 4 above that only stores the
|
||||
// size
|
||||
TYPE_PRIMITIVE,
|
||||
TYPE_PRIMITIVE = 6,
|
||||
//likely NULL
|
||||
TYPE_ALL_ELSE
|
||||
TYPE_ALL_ELSE = 7
|
||||
|
||||
} types;
|
||||
|
||||
@ -153,12 +153,12 @@ TableNode *getArrType(TableNode *definition) {
|
||||
// order, of what make up that type in an array. Unfortunately this second part
|
||||
// should probably instead be replaced by a reference to a scope in which those
|
||||
// elements are found.
|
||||
AdInfo *CreateRecordInfo(int length, TableNode *typesarray) {
|
||||
AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope) {
|
||||
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
|
||||
info->RecAdInfo = (record_info *)malloc(sizeof(record_info));
|
||||
info->RecAdInfo->numofelements = length;
|
||||
// replace below with reference to a scope, not an array
|
||||
info->RecAdInfo->listoftypes = typesarray;
|
||||
info->RecAdInfo->recordScope = recordScope;
|
||||
return info;
|
||||
}
|
||||
// This gets the number of elements that make up a record.
|
||||
@ -172,13 +172,13 @@ int getRecLength(TableNode *definition) {
|
||||
return definition->additionalinfo->RecAdInfo->numofelements;
|
||||
}
|
||||
// This gets the array. Needs to up be updated to get the scope instead
|
||||
TableNode *getRecList(TableNode *definition) {
|
||||
SymbolTable *getRecList(TableNode *definition) {
|
||||
if (strcmp(getType(definition), "record") != 0) {
|
||||
printf("not checking the list of types of a record -- invalid "
|
||||
"op\n");
|
||||
return NULL;
|
||||
}
|
||||
return definition->additionalinfo->RecAdInfo->listoftypes;
|
||||
return definition->additionalinfo->RecAdInfo->recordScope;
|
||||
}
|
||||
|
||||
// below function takes a bool to see if parameter should be decomposed or not
|
||||
@ -379,8 +379,34 @@ TableNode* boo;
|
||||
TableNode* recprime;
|
||||
TableNode* funtypeprime;
|
||||
*/
|
||||
TableNode* populateTypeAndInfo(TableNode* tn, TableNode* type, AdInfo* info){
|
||||
if(tn == NULL){
|
||||
printf("passed in an invalid table node to modify (NULL).\n");
|
||||
return NULL;
|
||||
}
|
||||
if(type == NULL){
|
||||
printf("passed in a NULL type reference to populate a table node. Invalid.\n");
|
||||
return NULL;
|
||||
}
|
||||
if(info == NULL){
|
||||
printf("passed in a NULL info reference to populate a table node. Invalid.\n");
|
||||
return NULL;
|
||||
}
|
||||
tn->theType = type;
|
||||
tn->additionalinfo = info;
|
||||
//returning reference to modified table node
|
||||
return tn;
|
||||
}
|
||||
|
||||
int getAdInfoType(TableNode* tn){
|
||||
if(tn == NULL){
|
||||
printf("passing in NULL table entry. Invalid\n");
|
||||
return -1;
|
||||
}
|
||||
if(tn->theType == NULL){
|
||||
printf("Entry being passed in has a null reference for theType. Invalid.\n");
|
||||
return -1;
|
||||
}
|
||||
if(strcmp(getType(tn),getName(integ))==0){
|
||||
return TYPE_PRIMITIVE;
|
||||
}
|
||||
@ -443,7 +469,16 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
||||
}
|
||||
}
|
||||
|
||||
char *getType(TableNode *tn) { return tn->theType->theName; }
|
||||
char *getType(TableNode *tn) {
|
||||
if(tn == NULL){
|
||||
printf("passed a NULL table entry to getType\n");
|
||||
return NULL;
|
||||
}
|
||||
if(tn->theType == NULL){
|
||||
printf("type of entry is currently NULL, undefined type \n");
|
||||
return NULL;
|
||||
}
|
||||
return tn->theType->theName; }
|
||||
char *getName(TableNode *tn) { return tn->theName; }
|
||||
int getLine(SymbolTable *st) { return st->Line_Number; }
|
||||
int getColumn(SymbolTable *st) { return st->Column_Number; }
|
||||
@ -483,6 +518,7 @@ names\n"); return NULL;
|
||||
|
||||
}
|
||||
*/
|
||||
//only check table that is given
|
||||
TableNode *table_lookup(SymbolTable *table, char *x) {
|
||||
TableNode *entrie = table->entries;
|
||||
for (; entrie != NULL; entrie = entrie->next) {
|
||||
@ -492,6 +528,7 @@ TableNode *table_lookup(SymbolTable *table, char *x) {
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
//check current table and all parents
|
||||
TableNode *look_up(SymbolTable *table, char *x) {
|
||||
if (table == NULL) {
|
||||
return NULL;
|
||||
@ -504,6 +541,8 @@ TableNode *look_up(SymbolTable *table, char *x) {
|
||||
}
|
||||
|
||||
void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
|
||||
return;
|
||||
if (table->Parent_Scope == NULL) {
|
||||
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
|
||||
"SCOPE", "PARENT", "TYPE", "Extra annotation");
|
||||
@ -526,7 +565,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "",
|
||||
current_scope, parant_scope, "", "Empty Scope");
|
||||
}
|
||||
for (; entrie != NULL; entrie = entrie->next) {
|
||||
for (entrie != NULL; entrie = entrie->next;) {
|
||||
if (parant_scope == 0) {
|
||||
/*have to update*/ if (strcmp(entrie->theType->theName,
|
||||
"function primitive") ||
|
||||
@ -555,7 +594,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
"----------------------\n");
|
||||
}
|
||||
}
|
||||
|
||||
//get top most symbol table
|
||||
SymbolTable *getAncestor(SymbolTable *table) {
|
||||
if (table->Parent_Scope == NULL) {
|
||||
// if table has no parent, return itself
|
||||
@ -594,6 +633,7 @@ SymbolTable *removeEntry(SymbolTable *scope, char *search) {
|
||||
return scope;
|
||||
}
|
||||
|
||||
//almost certainly don't need to use the below function since type checking happens by passing types up the grammar
|
||||
bool typeCheck(char *firstID, char *secondID) {
|
||||
|
||||
TableNode *entry1 = look_up(cur, firstID);
|
||||
|
@ -30,7 +30,7 @@ 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;
|
||||
struct TableNode *listoftypes;
|
||||
struct SymbolTable *recordScope;
|
||||
} record_info;
|
||||
|
||||
typedef struct {
|
||||
@ -91,7 +91,7 @@ int getPrimSize(TableNode *definition);
|
||||
int getNumArrDim(TableNode *definition);
|
||||
TableNode *getArrType(TableNode *definition);
|
||||
int getRecLength(TableNode *definition);
|
||||
TableNode *getRecList(TableNode *definition);
|
||||
SymbolTable *getRecList(TableNode *definition);
|
||||
int getStartLine(TableNode *definition);
|
||||
bool getAsKeyword(TableNode *definition);
|
||||
TableNode *getParameter(TableNode *definition);
|
||||
|
Reference in New Issue
Block a user