fixed issue with not printing array instances in symbol table

This commit is contained in:
Partho
2025-04-14 02:01:51 -04:00
parent 3fc7a6371a
commit 3baa95288a
3 changed files with 108 additions and 88 deletions

View File

@ -21,7 +21,7 @@
void yyerror(const char *err);
int token_tracker;
TableNode * tn;
int counter;
// int counter;
%}
%union {
@ -160,6 +160,7 @@ definition:
}
| ID {
printdebug("see function def rule 1\n");
TableNode *node = table_lookup(getAncestor(cur), $1);
if (node == undefined) {
@ -239,11 +240,9 @@ definition:
}
}
}
counter = 0;
//counter = 0;
printdebug("Created a new scope after seeing a function definition");
} idlist {
printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d", $1,$5);
} R_PAREN ASSIGN sblock //check sblock type
} idlist R_PAREN ASSIGN sblock //check sblock type
;
@ -278,24 +277,31 @@ function_declaration:
idlist:
ID
{
counter ++;
printdebug("idlist rule 1 ID: %s", $1);
TableNode *entry = getFirstEntry(cur);
int count = 1;
while(count<counter){
entry = getNextEntry(entry);
count++;
}
printdebug("RAAAAAAAAAAAAAAAAAAAAAAAAAAAAH");
printTableNode(entry);
while (strcmp(getName(entry),"undefined") != 0) {
while((getName(entry) != getName(undefined))){
entry = getNextEntry(entry);
}
if (getNextEntry(entry) == NULL) {
printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
if (entry == NULL){
printdebug("mismatch in number of parameters passed to function");
}
else if(entry->theName == NULL){
addName(entry, $1);
printdebug("name added to entry is %s", $1);
printdebug("name added to entry of type %s is %s in function parameter scope",getType(entry), $1);
} else {
printdebug("undefined types passed in to function scope. Improper.");
addName(entry, $1);
}
printTableNode(entry);
//while (strcmp(getName(entry),"undefined") != 0) {
// entry = getNextEntry(entry);
//}
//if (getNextEntry(entry) == NULL) {
// printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
//}
//addName(entry, $1);
//printdebug("name added to entry is %s", $1);
//printTableNode(entry);
}
COMMA idlist
{
@ -303,22 +309,25 @@ idlist:
}
| ID
{
counter ++;
{ printdebug("idlist rule 2 ID: %s", $1);
TableNode *entry = getFirstEntry(cur);
int count = 1;
while(count<counter){
entry = getNextEntry(entry);
count++;
}
while (strcmp(getName(entry),"undefined") != 0) {
while((getName(entry) != getName(undefined))){
entry = getNextEntry(entry);
}
if (getNextEntry(entry) != NULL) {
printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
if (entry == NULL){
printdebug("mismatch in number of parameters passed to function");
}
addName(entry, $<words>1);
$$ = 1;
else if(entry->theName == NULL){
addName(entry, $1);
printdebug("name added to entry of type %s is %s in function parameter scope",getType(entry), $1);
} else {
printdebug("undefined types passed in to function scope. Improper.");
addName(entry, $1);
}
printTableNode(entry);
printdebug("Name of entry is now %s", getName(entry));
printdebug("Type of entry is %s", getType(entry));
printdebug("tag is %d", getAdInfoType(entry));
}
;
@ -375,7 +384,7 @@ dblock:
setColumnNumber(cur,@1.first_line);
printdebug("Did not create a new scope when saw dblock, set line number to %d instead", @1.first_line);
} else{
cur = CreateScope(cur,@1.first_line,@1.first_column); // <----- What is this?
//cur = CreateScope(cur,@1.first_line,@1.first_column); // <----- What is this?
printdebug("Created a new scope when seeing a dblock");
}
}

View File

@ -1128,6 +1128,17 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, arrayType, " Type of Array");
}
}
if (getAdInfoType(entry) == TYPE_ARRAY) {
char *arrayType = (char *)malloc(100);
sprintf(arrayType, " %d -> %s", getNumArrDim(entry),
getName(getArrType(entry)));
if (parentScopeNum == 0) {
st_fprint(file_ptr, getName(entry), currentScopeNum, -100, getType(entry), " Array Instance");
} else {
st_fprint(file_ptr, getName(entry), currentScopeNum, parentScopeNum, getType(entry), " Array Instance");
}
}
if (getAdInfoType(entry) == TYPE_RECORD_TYPE) {
char *recordAdInfo = (char *)malloc(100);
sprintf(recordAdInfo, " elements-%d size-%d bytes", getRecLength(entry), getRecTotal(entry));

View File

@ -47,11 +47,11 @@ foo (x) := {
return x * x;
}
bar1 (a) := {
return a.x * a.y;
bar1(a,b) := {
return a * b;
}
bar2 as (r,s) := {
bar2(r,s) := {
if (r < s) then {
while (!(r < s)) {
r := r + 1;