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);
} else {
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:
L_BRACE
{
if (getLine(cur) != 0 && getColumn(cur)) {
if (getLine(cur) != 0) {
cur = CreateScope(cur,@1.first_line,@1.first_column);
} else {
setLineNumber(cur, @1.first_line);
setColumnNumber(cur,@1.first_line);
}
}
statement_list
@ -288,7 +291,16 @@ sblock:
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) {
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);
if (yyin != NULL) {
fclose(yyin);
@ -144,7 +153,8 @@ int run(FILE *alpha) {
yyparse();
FILE *f = fdopen(1, "w");
print_symbol_table(getAncestor(cur), f);
print_symbol_table(top, f);
fclose(f);
if (yyin != NULL) {

View File

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

View File

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