starting to work on grammar fixes

This commit is contained in:
Partho
2025-04-11 15:45:33 -04:00
parent f6dabd8d03
commit 3e1e159561
3 changed files with 24 additions and 8 deletions

View File

@ -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));
}
}

View File

@ -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");
}
}

View File

@ -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);