fixed issue with not printing array instances in symbol table
This commit is contained in:
@ -21,7 +21,7 @@
|
|||||||
void yyerror(const char *err);
|
void yyerror(const char *err);
|
||||||
int token_tracker;
|
int token_tracker;
|
||||||
TableNode * tn;
|
TableNode * tn;
|
||||||
int counter;
|
// int counter;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
@ -160,6 +160,7 @@ definition:
|
|||||||
}
|
}
|
||||||
|
|
||||||
| ID {
|
| ID {
|
||||||
|
printdebug("see function def rule 1\n");
|
||||||
TableNode *node = table_lookup(getAncestor(cur), $1);
|
TableNode *node = table_lookup(getAncestor(cur), $1);
|
||||||
if (node == undefined) {
|
if (node == undefined) {
|
||||||
|
|
||||||
@ -239,11 +240,9 @@ definition:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
counter = 0;
|
//counter = 0;
|
||||||
printdebug("Created a new scope after seeing a function definition");
|
printdebug("Created a new scope after seeing a function definition");
|
||||||
} idlist {
|
} idlist R_PAREN ASSIGN sblock //check sblock type
|
||||||
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
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -278,24 +277,31 @@ function_declaration:
|
|||||||
idlist:
|
idlist:
|
||||||
ID
|
ID
|
||||||
{
|
{
|
||||||
counter ++;
|
printdebug("idlist rule 1 ID: %s", $1);
|
||||||
TableNode *entry = getFirstEntry(cur);
|
TableNode *entry = getFirstEntry(cur);
|
||||||
int count = 1;
|
while((getName(entry) != getName(undefined))){
|
||||||
while(count<counter){
|
|
||||||
entry = getNextEntry(entry);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
printdebug("RAAAAAAAAAAAAAAAAAAAAAAAAAAAAH");
|
|
||||||
printTableNode(entry);
|
|
||||||
while (strcmp(getName(entry),"undefined") != 0) {
|
|
||||||
entry = getNextEntry(entry);
|
entry = getNextEntry(entry);
|
||||||
}
|
}
|
||||||
if (getNextEntry(entry) == NULL) {
|
if (entry == NULL){
|
||||||
printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
|
printdebug("mismatch in number of parameters passed to function");
|
||||||
}
|
}
|
||||||
|
else if(entry->theName == NULL){
|
||||||
addName(entry, $1);
|
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);
|
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
|
COMMA idlist
|
||||||
{
|
{
|
||||||
@ -303,22 +309,25 @@ idlist:
|
|||||||
}
|
}
|
||||||
|
|
||||||
| ID
|
| ID
|
||||||
{
|
{ printdebug("idlist rule 2 ID: %s", $1);
|
||||||
counter ++;
|
|
||||||
TableNode *entry = getFirstEntry(cur);
|
TableNode *entry = getFirstEntry(cur);
|
||||||
int count = 1;
|
while((getName(entry) != getName(undefined))){
|
||||||
while(count<counter){
|
|
||||||
entry = getNextEntry(entry);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
while (strcmp(getName(entry),"undefined") != 0) {
|
|
||||||
entry = getNextEntry(entry);
|
entry = getNextEntry(entry);
|
||||||
}
|
}
|
||||||
if (getNextEntry(entry) != NULL) {
|
if (entry == NULL){
|
||||||
printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
|
printdebug("mismatch in number of parameters passed to function");
|
||||||
}
|
}
|
||||||
addName(entry, $<words>1);
|
else if(entry->theName == NULL){
|
||||||
$$ = 1;
|
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);
|
setColumnNumber(cur,@1.first_line);
|
||||||
printdebug("Did not create a new scope when saw dblock, set line number to %d instead", @1.first_line);
|
printdebug("Did not create a new scope when saw dblock, set line number to %d instead", @1.first_line);
|
||||||
} else{
|
} 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");
|
printdebug("Created a new scope when seeing a dblock");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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");
|
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) {
|
if (getAdInfoType(entry) == TYPE_RECORD_TYPE) {
|
||||||
char *recordAdInfo = (char *)malloc(100);
|
char *recordAdInfo = (char *)malloc(100);
|
||||||
sprintf(recordAdInfo, " elements-%d size-%d bytes", getRecLength(entry), getRecTotal(entry));
|
sprintf(recordAdInfo, " elements-%d size-%d bytes", getRecLength(entry), getRecTotal(entry));
|
||||||
|
@ -47,11 +47,11 @@ foo (x) := {
|
|||||||
return x * x;
|
return x * x;
|
||||||
}
|
}
|
||||||
|
|
||||||
bar1 (a) := {
|
bar1(a,b) := {
|
||||||
return a.x * a.y;
|
return a * b;
|
||||||
}
|
}
|
||||||
|
|
||||||
bar2 as (r,s) := {
|
bar2(r,s) := {
|
||||||
if (r < s) then {
|
if (r < s) then {
|
||||||
while (!(r < s)) {
|
while (!(r < s)) {
|
||||||
r := r + 1;
|
r := r + 1;
|
||||||
|
Reference in New Issue
Block a user