latest
This commit is contained in:
@ -132,7 +132,9 @@ definition:
|
||||
| TYPE ID COLON C_INTEGER ARROW id_or_types
|
||||
{printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d",
|
||||
$2, $6, $4);
|
||||
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));}
|
||||
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));
|
||||
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, $6);
|
||||
}
|
||||
| function_declaration
|
||||
| TYPE ID COLON id_or_types ARROW id_or_types {
|
||||
printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s",
|
||||
@ -237,8 +239,12 @@ declaration_list:
|
||||
;
|
||||
|
||||
declaration:
|
||||
id_or_types COLON ID {printdebug("ID/TYPE: %s, ID: %s", $<words>1, $<words>3) ; CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
|
||||
;
|
||||
id_or_types COLON ID
|
||||
{
|
||||
printdebug("ID/TYPE: %s, ID: %s", $<words>1, $<words>3) ;
|
||||
CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL);
|
||||
}
|
||||
;
|
||||
|
||||
id_or_types:
|
||||
ID {printdebug("string of id is %s in ID pattern of id_or_type rule.", $1); $$ = $1;}
|
||||
@ -394,15 +400,21 @@ expression:
|
||||
// add array case
|
||||
// include type check for ablock in arrays - ablock is always the int of the elements in array/rec
|
||||
assignable:
|
||||
ID {$$ = getType(look_up(cur,$1)); printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);}
|
||||
| assignable
|
||||
ID
|
||||
{
|
||||
$$ = getType(look_up(cur,$1));
|
||||
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);}
|
||||
| assignable
|
||||
{
|
||||
printdebug("%sBeginning rule 2 of assignable.", COLOR_CYAN);
|
||||
cur = CreateScope(cur, -1,-1);
|
||||
}
|
||||
ablock
|
||||
{
|
||||
ablock {
|
||||
int type = getAdInfoType(look_up(getParent(cur), $1));
|
||||
printdebug("%stype is %d", COLOR_PURPLE, type);
|
||||
|
||||
if (type == TYPE_FUNCTION_DECLARATION) {
|
||||
printdebug("%sEntering function call", COLOR_LIGHTGREEN);
|
||||
if (getAsKeyword(look_up(getParent(cur), $1))) {
|
||||
TableNode *param = getParameter(look_up(getParent(cur), $1));
|
||||
SymbolTable *recList = getRecList(param);
|
||||
@ -414,7 +426,7 @@ assignable:
|
||||
//this isn't very efficient, but will hopefully work
|
||||
while (lastCheckedAct != NULL && lastCheckedRef != NULL) {
|
||||
if (strcmp(getName(lastCheckedAct), getName(lastCheckedRef)) != 0) {
|
||||
printdebug("expected %s expression in function call but got %s at line %d and column %d",getName(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
|
||||
printdebug("expected %s expression in function call but got %s at line %d and column %d",getType(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
|
||||
}
|
||||
lastCheckedAct = getNextEntry(lastCheckedAct);
|
||||
TableNode *tn = getFirstEntry(recList);
|
||||
@ -424,33 +436,39 @@ assignable:
|
||||
lastCheckedRef = tn;
|
||||
}
|
||||
|
||||
} else {
|
||||
char *expected = getName(getParameter(look_up(getParent(cur), $1)));
|
||||
char *actual = getType(getFirstEntry(cur));
|
||||
if (strcmp(expected, actual) != 0) {
|
||||
printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column);
|
||||
}
|
||||
}
|
||||
|
||||
$$ = getName(getReturn(table_lookup(getAncestor(cur), $1)));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
||||
} else if (type == TYPE_ARRAY) {
|
||||
if (getNumArrDim(look_up(getParent(cur), $1)) != $<integ>2) {
|
||||
printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, $1)), $<integ>2, @2.first_line, @2.first_column);
|
||||
}
|
||||
for (TableNode *tn = getFirstEntry(cur); tn != NULL; tn = getNextEntry(tn)) {
|
||||
if (strcmp(getName(tn), "integer") != 0) {
|
||||
printdebug("expected only integer expressions in array ablock at line %d column %d", @3.first_line, @3.first_column);
|
||||
}
|
||||
}
|
||||
$$ = getName(getArrType(look_up(getParent(cur), $1)));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
||||
}
|
||||
cur = getParent(cur);
|
||||
}
|
||||
| assignable rec_op ID {if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3)){
|
||||
{$$ = getName(table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3));}}; printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", $$, $1);}
|
||||
;
|
||||
} else {
|
||||
char *expected = getName(getParameter(look_up(getParent(cur), $1)));
|
||||
char *actual = getType(getFirstEntry(cur));
|
||||
if (strcmp(expected, actual) != 0) {
|
||||
printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column);
|
||||
}
|
||||
}
|
||||
$$ = getName(getReturn(table_lookup(getAncestor(cur), $1)));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
||||
|
||||
} else if (type == TYPE_ARRAY_TYPE) {
|
||||
printdebug("%sEntering array call", COLOR_LIGHTGREEN);
|
||||
if (getNumArrDim(look_up(getParent(cur), $1)) != $<integ>2) {
|
||||
printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, $1)), $<integ>2, @2.first_line, @2.first_column);
|
||||
}
|
||||
// for (TableNode *tn = getFirstEntry(cur); tn != NULL; tn = getNextEntry(tn)) {
|
||||
// if (strcmp(getName(tn), "integer") != 0) {
|
||||
// printdebug("expected only integer expressions in array ablock at line %d column %d", @3.first_line, @3.first_column);
|
||||
// }
|
||||
// }
|
||||
$$ = getName(getArrType(look_up(getParent(cur), $1)));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
||||
}
|
||||
cur = getParent(cur);
|
||||
}
|
||||
| assignable rec_op ID
|
||||
{
|
||||
if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3)) {
|
||||
$$ = getName(table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3));
|
||||
}
|
||||
printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", $$, $1);
|
||||
}
|
||||
;
|
||||
|
||||
memOp:
|
||||
RESERVE {printdebug("reserve expression");}
|
||||
|
@ -702,7 +702,7 @@ int getAdInfoType(TableNode *tn) {
|
||||
return TYPE_FUNCTION_TYPE;
|
||||
}
|
||||
if (strcmp(getName(tn), getName(arrayprim)) == 0) {
|
||||
return TYPE_ARRAY;
|
||||
return TYPE_ARRAY_TYPE; // changed from TYPE_ARRAY cuz
|
||||
}
|
||||
if (strcmp(getName(tn), getName(undefined)) == 0) {
|
||||
return TYPE_UNDEFINED;
|
||||
@ -713,7 +713,7 @@ int getAdInfoType(TableNode *tn) {
|
||||
}
|
||||
if(strcmp(getType(tn), getName(arrayprim))==0){
|
||||
printdebug("passed in an array to getAdInfoType");
|
||||
return TYPE_ARRAY;
|
||||
return TYPE_ARRAY_TYPE;
|
||||
}
|
||||
if(strcmp(getType(tn), getName(recprime))==0){
|
||||
printdebug("passed in a record to getAdInfoType");
|
||||
@ -1004,8 +1004,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
int parant_scope = 0;
|
||||
int current_scope = 0;
|
||||
if (table->Parent_Scope != NULL) {
|
||||
parant_scope = table->Parent_Scope->Line_Number * 1000 +
|
||||
table->Parent_Scope->Column_Number;
|
||||
parant_scope = getParent(table)->Line_Number * 1000 +
|
||||
getParent(table)->Column_Number;
|
||||
current_scope =
|
||||
table->Line_Number * 1000 + table->Column_Number;
|
||||
} else {
|
||||
@ -1015,8 +1015,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "",
|
||||
current_scope, parant_scope, "", "Empty Scope");
|
||||
}
|
||||
for (; entrie != NULL; entrie = entrie->next) {
|
||||
if (getAdInfoType(entrie) == TYPE_ARRAY) {
|
||||
for (; entrie != NULL; entrie = getNextEntry(entrie)) {
|
||||
if (getAdInfoType(entrie) == TYPE_ARRAY_TYPE) {
|
||||
if (parant_scope == 0) {
|
||||
|
||||
fprintf(file_ptr,
|
||||
@ -1136,13 +1136,13 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (table->Children_Scope != NULL) {
|
||||
ListOfTable *node = table->Children_Scope;
|
||||
if (getChildren(table) != NULL) {
|
||||
ListOfTable *node = getChildren(table);
|
||||
for (; node != NULL; node = node->next) {
|
||||
print_symbol_table(node->table, file_ptr);
|
||||
}
|
||||
}
|
||||
if (table->Parent_Scope == NULL) {
|
||||
if (getParent(table) == NULL) {
|
||||
fprintf(file_ptr, "-----------------:--------:--------:--------"
|
||||
"--------------:-------"
|
||||
"----------------------\n");
|
||||
|
@ -20,6 +20,6 @@ entry(arg) := {
|
||||
many_names(2)(2) := 'r';
|
||||
many_names(2)(3) := 't';
|
||||
many_names(2)(4) := 'h';
|
||||
many_names(2)(5) := 'o';
|
||||
0(2)(5) := 'o';
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user