From 3e1e159561443ac2bfb275ec0b3e28cd6f9947df Mon Sep 17 00:00:00 2001 From: Partho Date: Fri, 11 Apr 2025 15:45:33 -0400 Subject: [PATCH] starting to work on grammar fixes --- src/grammar.y | 14 ++++++++------ src/symbol_table.c | 15 ++++++++++++++- src/symbol_table.h | 3 ++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 651c5ae..24b7d15 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -174,14 +174,15 @@ definition: } L_PAREN { TableNode * parameter = getParameter(getTypeEntry(table_lookup(getAncestor(cur), $1))); //TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1)))); - printdebug("parameter type: %s", getType(parameter)); + printdebug("type of parameter: %s", getName(parameter)); if (parameter == undefined) { printdebug("[TYPE CHECK] function defined with as, but parameter is undefined at line %d, column %d", @1.first_line, @1.first_column); - }else if(getAdInfoType(parameter) != TYPE_RECORD){ - int type_of_param_type = getAdInfoType(parameter); + }else if(getAdInfoType(parameter) != TYPE_RECORD_TYPE){ + int type_of_param_type = getAdInfoType(parameter);//this is an enum value defined in symbol_table.h if( type_of_param_type == TYPE_UNDEFINED || type_of_param_type == TYPE_FUNCTION_DECLARATION || type_of_param_type == TYPE_ARRAY + || type_of_param_type == TYPE_PRIMITIVE || type_of_param_type == TYPE_ALL_ELSE || type_of_param_type == TYPE_SYSTEM_DEFINED || type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused @@ -355,7 +356,7 @@ declaration: printdebug("ID/TYPE: %s, ID: %s", getName((TableNode*)$1), $3) ; int d = getAdInfoType((TableNode*)$1); if(d == TYPE_UNDEFINED) { - printdebug("undefined type at line %d and column %d", @2.first_line, @2.first_column); + printdebug("[TYPE CHECK] undefined type at line %d and column %d", @2.first_line, @2.first_column); CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1)); } else if(d == TYPE_FUNCTION_TYPE) { @@ -373,11 +374,12 @@ declaration: d = TYPE_RECORD; CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1)); } - else if(d == TYPE_PRIMITIVE){ + else if(d == TYPE_PRIMITIVE_TYPE){ printdebug("primitive variable at line %d and column %d", @2.first_line, @2.first_column); + d = TYPE_PRIMITIVE; CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1)); }else { - printdebug("other invalid type passed at %d and column %d", @2.first_line, @2.first_column); + printdebug("[TYPE CHECK] other invalid type passed at %d and column %d", @2.first_line, @2.first_column); CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1)); } } diff --git a/src/symbol_table.c b/src/symbol_table.c index 1283d6a..60752bd 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -1142,6 +1142,19 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } } + if (getAdInfoType(entry) == TYPE_PRIMITIVE_TYPE) { + char *primAdInfo = (char *)malloc(100); + sprintf(primAdInfo, " size-%d bytes", getPrimSize(getTypeEntry(entry))); + if (parentScopeNum == 0) { + st_fprint(file_ptr, getName(entry), currentScopeNum, -100, " Primitive Type", primAdInfo); + } else { + //printdebug("%sTHIS ONE", COLOR_RED); + printTableNode(entry); + char *primType = (char *)malloc(sizeof(getType(entry) + 1)); + sprintf(primType, " %s", getType(entry)); + st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, primType, primAdInfo); + } + } if (getAdInfoType(entry) == TYPE_PRIMITIVE) { char *primAdInfo = (char *)malloc(100); sprintf(primAdInfo, " size-%d bytes", getPrimSize(getTypeEntry(entry))); @@ -1152,7 +1165,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { printTableNode(entry); char *primType = (char *)malloc(sizeof(getType(entry) + 1)); sprintf(primType, " %s", getType(entry)); - st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, primType, primAdInfo); + st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, getType(entry), "Primitive Instance"); } } diff --git a/src/symbol_table.h b/src/symbol_table.h index af2d827..5f04f7c 100644 --- a/src/symbol_table.h +++ b/src/symbol_table.h @@ -79,7 +79,8 @@ typedef enum { TYPE_UNDEFINED = 8, TYPE_RECORD = 9, TYPE_ARRAY = 10, - TYPE_SYSTEM_DEFINED = 11 + TYPE_SYSTEM_DEFINED = 11, + TYPE_PRIMITIVE_TYPE = 12 } types; AdInfo *CreatePrimitiveInfo(int size);