continuing. need fix of makefile
This commit is contained in:
17
Makefile
17
Makefile
@ -33,22 +33,21 @@ runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o
|
|||||||
debug: CFLAGS += -DDEBUG=1
|
debug: CFLAGS += -DDEBUG=1
|
||||||
debug: clean compiler
|
debug: clean compiler
|
||||||
|
|
||||||
test: test-s1 test-s3 test-s2
|
test: test-s1 test-s2 test-s3
|
||||||
|
|
||||||
test-s1:
|
test-s1:
|
||||||
chmod +x ./check.sh
|
chmod +x ./check.sh
|
||||||
$(foreach test, $(TESTS-S1), ./$(EXE) -tok $(test);)
|
for test in $(TESTS-S1); do ./$(EXE) -tok $$test || echo "Test $$test failed but continuing"; done
|
||||||
./check.sh
|
|
||||||
|
|
||||||
|
|
||||||
test-s3:
|
|
||||||
chmod +x ./check.sh
|
|
||||||
$(foreach test, $(TESTS-S3), ./$(EXE) -st $(test);)
|
|
||||||
./check.sh
|
./check.sh
|
||||||
|
|
||||||
test-s2:
|
test-s2:
|
||||||
chmod +x ./check.sh
|
chmod +x ./check.sh
|
||||||
$(foreach test, $(TESTS-S2), ./$(EXE) -st $(test);)
|
for test in $(TESTS-S2); do ./$(EXE) -st $$test || echo "Test $$test failed but continuing"; done
|
||||||
|
./check.sh
|
||||||
|
|
||||||
|
test-s3:
|
||||||
|
chmod +x ./check.sh
|
||||||
|
for test in $(TESTS-S3); do ./$(EXE) -st $$test || echo "Test $$test failed but continuing"; done
|
||||||
./check.sh
|
./check.sh
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -219,8 +219,11 @@ declaration:
|
|||||||
;
|
;
|
||||||
|
|
||||||
id_or_types:
|
id_or_types:
|
||||||
ID {printf("string of id in id_or_type is %s\n",$<words>1); $$ = getType(look_up(cur,$1));}
|
ID {printf("string of id is %s in ID pattern of id_or_type rule.\n"); $$ = $1;}
|
||||||
| types {printf("string of type in id_or_type is %s\n",$<words>1);} {$$ = $<words>1;}
|
//{printf("string of id is %s in ID pattern of id_or_type rule. Type passed up the tree is %s.\n",$1,getType(look_up(cur,$1))); $$ = getType(look_up(cur,$1));}
|
||||||
|
| types {printf("string of type is %s in types pattern of id_or_type rule.\n",$1);} {$$ = $1;}
|
||||||
|
//{printf("string of type is %s in types pattern of id_or_type rule. That is passed up the tree.\n",$<words>1);} {$$ = $<words>1;}
|
||||||
|
;
|
||||||
;
|
;
|
||||||
|
|
||||||
statement_list:
|
statement_list:
|
||||||
@ -247,7 +250,7 @@ simple_statement:
|
|||||||
|
|
||||||
assignable:
|
assignable:
|
||||||
ID {$$ = getType(look_up(cur,$1));}
|
ID {$$ = getType(look_up(cur,$1));}
|
||||||
| assignable ablock {$$ = getName(getReturn(look_up(cur, $1)));}
|
| assignable ablock {$$ = getName(getReturn(look_up(cur, $1)));} //add array case here
|
||||||
| assignable rec_op ID {if(undefined != table_lookup(getRecList(look_up(cur, $1)), $3)){
|
| assignable rec_op ID {if(undefined != table_lookup(getRecList(look_up(cur, $1)), $3)){
|
||||||
{$$ = getName(table_lookup(getRecList(look_up(cur, $1)), $3));}};}
|
{$$ = getName(table_lookup(getRecList(look_up(cur, $1)), $3));}};}
|
||||||
;
|
;
|
||||||
@ -360,10 +363,10 @@ constant:
|
|||||||
types:
|
types:
|
||||||
// Commented out T_String below
|
// Commented out T_String below
|
||||||
// T_STRING {printf("string of T_STRING in types is %s\n",$<words>1);} {$$ = $<words>1;}
|
// T_STRING {printf("string of T_STRING in types is %s\n",$<words>1);} {$$ = $<words>1;}
|
||||||
T_INTEGER {printf("string of T_INTEGER in types is %s\n",$<words>1);} {$$ = $<words>1;}
|
T_INTEGER {printf("string of T_INTEGER in types is %s\n",$<words>1);} {$$ = $1;}
|
||||||
| T_ADDRESS {printf("string of T_ADDRESS in types is %s\n",$<words>1);} {$$ = $<words>1;}
|
| T_ADDRESS {printf("string of T_ADDRESS in types is %s\n",$<words>1);} {$$ = $1;}
|
||||||
| T_CHARACTER {printf("string of T_CHARACTER in types is %s\n",$<words>1);} {$$ = $<words>1;}
|
| T_CHARACTER {printf("string of T_CHARACTER in types is %s\n",$<words>1);} {$$ = $1;}
|
||||||
| T_BOOLEAN {printf("string of T_BOOLEAN in types is %s\n",$<words>1);} {$$ = $<words>1;}
|
| T_BOOLEAN {printf("string of T_BOOLEAN in types is %s\n",$<words>1);} {$$ = $1;}
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
@ -650,7 +650,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->Parent_Scope == NULL) {
|
if (table->Parent_Scope == NULL) {
|
||||||
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
|
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
|
||||||
"SCOPE", "PARENT", "TYPE", "Extra annotation");
|
"SCOPE", "PARENT", "TYPE", "Extra annotation");
|
||||||
@ -674,84 +673,20 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
|||||||
current_scope, parant_scope, "", "Empty Scope");
|
current_scope, parant_scope, "", "Empty Scope");
|
||||||
}
|
}
|
||||||
for (; entrie != NULL; entrie = entrie->next) {
|
for (; entrie != NULL; entrie = entrie->next) {
|
||||||
if (getAdInfoType(entrie) == TYPE_ARRAY){
|
|
||||||
if (parant_scope == 0) {
|
if (parant_scope == 0) {
|
||||||
|
/*have to update*/ if (strcmp(entrie->theType->theName,
|
||||||
fprintf(file_ptr,
|
"function primitive") ||
|
||||||
"%-17s: %06d : : %-21d -> %-21s: %-28s\n",
|
strcmp(entrie->theType->theName,
|
||||||
entrie->theName, current_scope,
|
"array")) {
|
||||||
entrie->additionalinfo->ArrayAdInfo->numofdimensions,
|
|
||||||
entrie->additionalinfo->ArrayAdInfo->typeofarray->theName,
|
|
||||||
"Type of Array");
|
|
||||||
} else {
|
|
||||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n",
|
|
||||||
entrie->theName, current_scope, parant_scope,
|
|
||||||
entrie->additionalinfo->ArrayAdInfo->numofdimensions,
|
|
||||||
entrie->additionalinfo->ArrayAdInfo->typeofarray->theName,
|
|
||||||
"Type of Array");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (getAdInfoType(entrie) == TYPE_RECORD){
|
|
||||||
if (parant_scope == 0) {
|
|
||||||
|
|
||||||
fprintf(file_ptr,
|
|
||||||
"%-17s: %06d : :%-21s: elements-%-28d\n",
|
|
||||||
entrie->theName, current_scope,
|
|
||||||
"record",
|
|
||||||
entrie->additionalinfo->RecAdInfo->numofelements);
|
|
||||||
} else {
|
|
||||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: elements-%-28d\n",
|
|
||||||
entrie->theName, current_scope, parant_scope,
|
|
||||||
"record",
|
|
||||||
entrie->additionalinfo->RecAdInfo->numofelements);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (getAdInfoType(entrie) == TYPE_PRIMITIVE){
|
|
||||||
if (parant_scope == 0) {
|
|
||||||
|
|
||||||
fprintf(file_ptr,
|
|
||||||
"%-17s: %06d : :%-21s: size-%-28d bytes\n",
|
|
||||||
entrie->theName, current_scope,
|
|
||||||
"Primitive",
|
|
||||||
entrie->additionalinfo->PrimAdInfo->size);
|
|
||||||
} else {
|
|
||||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: size-%-28d bytes\n",
|
|
||||||
entrie->theName, current_scope, parant_scope,
|
|
||||||
"Primitive",
|
|
||||||
entrie->additionalinfo->PrimAdInfo->size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE){
|
|
||||||
if (parant_scope == 0) {
|
|
||||||
|
|
||||||
fprintf(file_ptr,
|
|
||||||
"%-17s: %06d : : %-21s -> %-21s: %-28s\n",
|
|
||||||
entrie->theName, current_scope,
|
|
||||||
entrie->additionalinfo->FunTypeAdInfo->parameter->theName,
|
|
||||||
entrie->additionalinfo->FunTypeAdInfo->returntype->theName,
|
|
||||||
"Type of Function");
|
|
||||||
} else {
|
|
||||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s -> %-21s: %-28s\n",
|
|
||||||
entrie->theName, current_scope, parant_scope,
|
|
||||||
entrie->additionalinfo->FunTypeAdInfo->parameter->theName,
|
|
||||||
entrie->additionalinfo->FunTypeAdInfo->returntype->theName,
|
|
||||||
"Type of Function");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION){
|
|
||||||
if (parant_scope == 0) {
|
|
||||||
|
|
||||||
fprintf(file_ptr,
|
fprintf(file_ptr,
|
||||||
"%-17s: %06d : : %-21s: %-28s\n",
|
"%-17s: %06d : : %-21s: %-28s\n",
|
||||||
entrie->theName, current_scope,
|
entrie->theName, current_scope,
|
||||||
getType(entrie),
|
entrie->theType->theName, "Extra annotation");
|
||||||
"Function");
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n",
|
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n",
|
||||||
entrie->theName, current_scope, parant_scope,
|
entrie->theName, current_scope, parant_scope,
|
||||||
getType(entrie),
|
entrie->theType->theName, "Extra annotation");
|
||||||
"Function");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (table->Children_Scope != NULL) {
|
if (table->Children_Scope != NULL) {
|
||||||
@ -766,6 +701,123 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
|||||||
"----------------------\n");
|
"----------------------\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||||
|
|
||||||
|
// if (table->Parent_Scope == NULL) {
|
||||||
|
// fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
|
||||||
|
// "SCOPE", "PARENT", "TYPE", "Extra annotation");
|
||||||
|
// }
|
||||||
|
// TableNode *entrie = table->entries;
|
||||||
|
// fprintf(file_ptr, "-----------------:--------:--------:----------------"
|
||||||
|
// "------:---------"
|
||||||
|
// "--------------------\n");
|
||||||
|
// 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;
|
||||||
|
// current_scope =
|
||||||
|
// table->Line_Number * 1000 + table->Column_Number;
|
||||||
|
// } else {
|
||||||
|
// current_scope = 1001;
|
||||||
|
// }
|
||||||
|
// if (entrie == NULL) {
|
||||||
|
// 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){
|
||||||
|
// if (parant_scope == 0) {
|
||||||
|
|
||||||
|
// fprintf(file_ptr,
|
||||||
|
// "%-17s: %06d : : %-21d -> %-21s: %-28s\n",
|
||||||
|
// entrie->theName, current_scope,
|
||||||
|
// entrie->additionalinfo->ArrayAdInfo->numofdimensions,
|
||||||
|
// entrie->additionalinfo->ArrayAdInfo->typeofarray->theName,
|
||||||
|
// "Type of Array");
|
||||||
|
// } else {
|
||||||
|
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n",
|
||||||
|
// entrie->theName, current_scope, parant_scope,
|
||||||
|
// entrie->additionalinfo->ArrayAdInfo->numofdimensions,
|
||||||
|
// entrie->additionalinfo->ArrayAdInfo->typeofarray->theName,
|
||||||
|
// "Type of Array");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (getAdInfoType(entrie) == TYPE_RECORD){
|
||||||
|
// if (parant_scope == 0) {
|
||||||
|
|
||||||
|
// fprintf(file_ptr,
|
||||||
|
// "%-17s: %06d : :%-21s: elements-%-28d\n",
|
||||||
|
// entrie->theName, current_scope,
|
||||||
|
// "record",
|
||||||
|
// entrie->additionalinfo->RecAdInfo->numofelements);
|
||||||
|
// } else {
|
||||||
|
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: elements-%-28d\n",
|
||||||
|
// entrie->theName, current_scope, parant_scope,
|
||||||
|
// "record",
|
||||||
|
// entrie->additionalinfo->RecAdInfo->numofelements);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (getAdInfoType(entrie) == TYPE_PRIMITIVE){
|
||||||
|
// if (parant_scope == 0) {
|
||||||
|
|
||||||
|
// fprintf(file_ptr,
|
||||||
|
// "%-17s: %06d : :%-21s: size-%-28d bytes\n",
|
||||||
|
// entrie->theName, current_scope,
|
||||||
|
// "Primitive",
|
||||||
|
// entrie->additionalinfo->PrimAdInfo->size);
|
||||||
|
// } else {
|
||||||
|
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: size-%-28d bytes\n",
|
||||||
|
// entrie->theName, current_scope, parant_scope,
|
||||||
|
// "Primitive",
|
||||||
|
// entrie->additionalinfo->PrimAdInfo->size);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE){
|
||||||
|
// if (parant_scope == 0) {
|
||||||
|
|
||||||
|
// fprintf(file_ptr,
|
||||||
|
// "%-17s: %06d : : %-21s -> %-21s: %-28s\n",
|
||||||
|
// entrie->theName, current_scope,
|
||||||
|
// entrie->additionalinfo->FunTypeAdInfo->parameter->theName,
|
||||||
|
// entrie->additionalinfo->FunTypeAdInfo->returntype->theName,
|
||||||
|
// "Type of Function");
|
||||||
|
// } else {
|
||||||
|
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s -> %-21s: %-28s\n",
|
||||||
|
// entrie->theName, current_scope, parant_scope,
|
||||||
|
// entrie->additionalinfo->FunTypeAdInfo->parameter->theName,
|
||||||
|
// entrie->additionalinfo->FunTypeAdInfo->returntype->theName,
|
||||||
|
// "Type of Function");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION){
|
||||||
|
// if (parant_scope == 0) {
|
||||||
|
|
||||||
|
// fprintf(file_ptr,
|
||||||
|
// "%-17s: %06d : :%-21s: %-28s\n",
|
||||||
|
// entrie->theName, current_scope,
|
||||||
|
// getType(entrie),
|
||||||
|
// "Function");
|
||||||
|
// } else {
|
||||||
|
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n",
|
||||||
|
// entrie->theName, current_scope, parant_scope,
|
||||||
|
// getType(entrie),
|
||||||
|
// "Function");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (table->Children_Scope != NULL) {
|
||||||
|
// ListOfTable *node = table->Children_Scope;
|
||||||
|
// for (; node != NULL; node = node->next) {
|
||||||
|
// print_symbol_table(node->table, file_ptr);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (table->Parent_Scope == NULL) {
|
||||||
|
// fprintf(file_ptr, "-----------------:--------:--------:--------"
|
||||||
|
// "--------------:-------"
|
||||||
|
// "----------------------\n");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
//get top most symbol table
|
//get top most symbol table
|
||||||
SymbolTable *getAncestor(SymbolTable *table) {
|
SymbolTable *getAncestor(SymbolTable *table) {
|
||||||
if(table == NULL){
|
if(table == NULL){
|
||||||
|
Reference in New Issue
Block a user