Ready for Dev! 🎉

This commit is contained in:
Scarlett
2025-04-04 15:42:50 -04:00
parent 4e862d54a4
commit d1aa7f7e0f
4 changed files with 55 additions and 33 deletions

View File

@ -196,7 +196,7 @@ definition:
printdebug("function defined with as, but parameter is type %s at line %d, column %d", getType(parameter),@1.first_line, @1.first_column); printdebug("function defined with as, but parameter is type %s at line %d, column %d", getType(parameter),@1.first_line, @1.first_column);
} else { } else {
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)) { for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)) {
CreateEntry(cur, entry, NULL, NULL); CreateEntry(cur, entry->theType, NULL, NULL);
} }
} }
} }
@ -258,8 +258,11 @@ idlist:
sblock: sblock:
L_BRACE L_BRACE
{ {
if (getLine(cur) != 0 && getColumn(cur)) { if (getLine(cur) != 0) {
cur = CreateScope(cur,@1.first_line,@1.first_column); cur = CreateScope(cur,@1.first_line,@1.first_column);
} else {
setLineNumber(cur, @1.first_line);
setColumnNumber(cur,@1.first_line);
} }
} }
statement_list statement_list
@ -288,7 +291,16 @@ sblock:
dblock: dblock:
L_BRACKET declaration_list R_BRACKET; L_BRACKET
{
if(getLine(cur)==0) {
setLineNumber(cur, @1.first_line);
setColumnNumber(cur,@1.first_line);
} else {
cur = CreateScope(cur,@1.first_line,@1.first_column);
}
}
declaration_list R_BRACKET;

View File

@ -134,7 +134,16 @@ int run(FILE *alpha) {
if (st_flag != NULL) { if (st_flag != NULL) {
yyparse(); yyparse();
print_symbol_table(getAncestor(cur), st_flag);
if (cur == NULL) {
printdebug("%s[FATAL] cur is null", COLOR_LIGHTRED);
}
if (top == NULL) {
printdebug("%s[FATAL] top is null", COLOR_LIGHTRED);
}
print_symbol_table(top, st_flag);
fclose(st_flag); fclose(st_flag);
if (yyin != NULL) { if (yyin != NULL) {
fclose(yyin); fclose(yyin);
@ -144,7 +153,8 @@ int run(FILE *alpha) {
yyparse(); yyparse();
FILE *f = fdopen(1, "w"); FILE *f = fdopen(1, "w");
print_symbol_table(getAncestor(cur), f);
print_symbol_table(top, f);
fclose(f); fclose(f);
if (yyin != NULL) { if (yyin != NULL) {

View File

@ -186,7 +186,7 @@ int getRecSize(SymbolTable *tn) {
"passed in NULL SymbolTable for getRecSize. Invalid"); "passed in NULL SymbolTable for getRecSize. Invalid");
return -1; return -1;
} }
int s = 0; int s = 1;
TableNode *cur = getFirstEntry(tn); TableNode *cur = getFirstEntry(tn);
if (cur != NULL) { if (cur != NULL) {
while (getNextEntry(cur) != NULL) { while (getNextEntry(cur) != NULL) {
@ -772,7 +772,6 @@ TableNode *look_up(SymbolTable *table, char *x) {
} }
void print_symbol_table(SymbolTable *table, FILE *file_ptr) { void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (table == NULL) { if (table == NULL) {
printdebug( printdebug(
"%s[FATAL] passed in NULL table to print_symbol_table", "%s[FATAL] passed in NULL table to print_symbol_table",
@ -781,14 +780,14 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
} }
if (table->Parent_Scope == NULL) { if (table->Parent_Scope == NULL) {
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", fprintf(file_ptr, "%-25s: %-6s : %-6s : %-25s: %-30s\n", "NAME",
"SCOPE", "PARENT", "TYPE", "Extra annotation"); "SCOPE", "PARENT", "TYPE", "Extra annotation");
} }
TableNode *entrie = table->entries; TableNode *entrie = table->entries;
fprintf(file_ptr, "-----------------:--------:--------:----------------" fprintf(file_ptr,
"------:---------" "-------------------------:--------:--------:------------------"
"--------------------\n"); "--------:------------------------------\n");
int parant_scope = 0; int parant_scope = 0;
int current_scope = 0; int current_scope = 0;
if (table->Parent_Scope != NULL) { if (table->Parent_Scope != NULL) {
@ -800,7 +799,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
current_scope = 1001; current_scope = 1001;
} }
if (entrie == NULL) { if (entrie == NULL) {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "", fprintf(file_ptr, "%-25s: %06d : %06d : %-25s: %-30s\n", "",
current_scope, parant_scope, "", "Empty Scope"); current_scope, parant_scope, "", "Empty Scope");
} }
for (; entrie != NULL; entrie = getNextEntry(entrie)) { for (; entrie != NULL; entrie = getNextEntry(entrie)) {
@ -808,8 +807,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : : %-21d -> " "%-25s: %06d : : %d -> %-20s: "
"%-21s: %-28s\n", "%-30s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
entrie->additionalinfo->ArrayAdInfo entrie->additionalinfo->ArrayAdInfo
->numofdimensions, ->numofdimensions,
@ -818,8 +817,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
"Type of Array"); "Type of Array");
} else { } else {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : %06d : %-21d -> %-21s: " "%-25s: %06d : : %d -> %-20s: "
"%-28s\n", "%-30s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
parant_scope, parant_scope,
entrie->additionalinfo->ArrayAdInfo entrie->additionalinfo->ArrayAdInfo
@ -833,16 +832,16 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : :%-21s: " "%-25s: %06d : : %-25s: "
"elements-%-28d\n", "elements-%-30d\n",
entrie->theName, current_scope, entrie->theName, current_scope,
"record", "record",
entrie->additionalinfo->RecAdInfo entrie->additionalinfo->RecAdInfo
->numofelements); ->numofelements);
} else { } else {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : %06d : %-21s: " "%-25s: %06d : %06d : %-25s: "
"elements-%-28d\n", "elements-%-30d\n",
entrie->theName, current_scope, entrie->theName, current_scope,
parant_scope, "record", parant_scope, "record",
entrie->additionalinfo->RecAdInfo entrie->additionalinfo->RecAdInfo
@ -854,14 +853,14 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
fprintf( fprintf(
file_ptr, file_ptr,
"%-17s: %06d : :%-21s: size-%-28d " "%-25s: %06d : : %-25s: size-%d "
"bytes\n", "bytes\n",
entrie->theName, current_scope, "Primitive", entrie->theName, current_scope, "Primitive",
entrie->additionalinfo->PrimAdInfo->size); entrie->additionalinfo->PrimAdInfo->size);
} else { } else {
fprintf( fprintf(
file_ptr, file_ptr,
"%-17s: %06d : %06d : %-21s: size-%-28d " "%-25s: %06d : %06d : %-25s: size-%-30d "
"bytes\n", "bytes\n",
entrie->theName, current_scope, entrie->theName, current_scope,
parant_scope, "Primitive", parant_scope, "Primitive",
@ -872,8 +871,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : : %-21s -> " "%-25s: %06d : : %-25s -> "
"%-21s: %-28s\n", "%-25s: %-30s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
entrie->additionalinfo->FunTypeAdInfo entrie->additionalinfo->FunTypeAdInfo
->parameter->theName, ->parameter->theName,
@ -882,8 +881,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
"Type of Function"); "Type of Function");
} else { } else {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : %06d : %-21s -> %-21s: " "%-25s: %06d : %06d : %-25s -> %-21s: "
"%-28s\n", "%-30s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
parant_scope, parant_scope,
entrie->additionalinfo->FunTypeAdInfo entrie->additionalinfo->FunTypeAdInfo
@ -897,12 +896,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : :%-21s: %-28s\n", "%-25s: %06d : : %-25s: %-30s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
getType(entrie), "User Defined"); getType(entrie), "User Defined");
} else { } else {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : %06d : %-21s: %-28s\n", "%-25s: %06d : %06d : %-25s: %-30s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
parant_scope, getType(entrie), parant_scope, getType(entrie),
"User Defined"); "User Defined");
@ -912,12 +911,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : :%-21s: %-28s\n", "%-25s: %06d : : %-25s: %-30s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
"undefined", "undefined entry"); "undefined", "undefined entry");
} else { } else {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : %06d : %-21s: %-28s\n", "%-25s: %06d : %06d : %-25s: %-30s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
parant_scope, "undefined", parant_scope, "undefined",
"undefined entry"); "undefined entry");
@ -940,9 +939,9 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
} }
} }
if (getParent(table) == NULL) { if (getParent(table) == NULL) {
fprintf(file_ptr, "-----------------:--------:--------:--------" fprintf(file_ptr,
"--------------:-------" "-------------------------:--------:--------:----------"
"----------------------\n"); "----------------:------------------------------\n");
} }
} }
// get top most symbol table // get top most symbol table

View File

@ -9,6 +9,7 @@ function foo : T1
function bar1 : T2 function bar1 : T2
function bar2 : T2 function bar2 : T2
function make_list : list function make_list : list
make_list(a) := { make_list(a) := {
[integer:orig_a; address: ret; address: curr; address: temp] [integer:orig_a; address: ret; address: curr; address: temp]
if (a < 0 | a = 0) then { if (a < 0 | a = 0) then {