diff --git a/Makefile b/Makefile index 729ca3d..c58b895 100644 --- a/Makefile +++ b/Makefile @@ -33,22 +33,21 @@ runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o debug: CFLAGS += -DDEBUG=1 debug: clean compiler -test: test-s1 test-s3 test-s2 +test: test-s1 test-s2 test-s3 test-s1: chmod +x ./check.sh - $(foreach test, $(TESTS-S1), ./$(EXE) -tok $(test);) - ./check.sh - - -test-s3: - chmod +x ./check.sh - $(foreach test, $(TESTS-S3), ./$(EXE) -st $(test);) + for test in $(TESTS-S1); do ./$(EXE) -tok $$test || echo "Test $$test failed but continuing"; done ./check.sh test-s2: 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 clean: diff --git a/src/grammar.y b/src/grammar.y index 5238aac..fcb06b8 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -219,8 +219,11 @@ declaration: ; id_or_types: - ID {printf("string of id in id_or_type is %s\n",$1); $$ = getType(look_up(cur,$1));} - | types {printf("string of type in id_or_type is %s\n",$1);} {$$ = $1;} + ID {printf("string of id is %s in ID pattern of id_or_type rule.\n"); $$ = $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",$1);} {$$ = $1;} + ; ; statement_list: @@ -247,7 +250,7 @@ simple_statement: assignable: 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)){ {$$ = getName(table_lookup(getRecList(look_up(cur, $1)), $3));}};} ; @@ -360,10 +363,10 @@ constant: types: // Commented out T_String below // T_STRING {printf("string of T_STRING in types is %s\n",$1);} {$$ = $1;} - T_INTEGER {printf("string of T_INTEGER in types is %s\n",$1);} {$$ = $1;} - | T_ADDRESS {printf("string of T_ADDRESS in types is %s\n",$1);} {$$ = $1;} - | T_CHARACTER {printf("string of T_CHARACTER in types is %s\n",$1);} {$$ = $1;} - | T_BOOLEAN {printf("string of T_BOOLEAN in types is %s\n",$1);} {$$ = $1;} + T_INTEGER {printf("string of T_INTEGER in types is %s\n",$1);} {$$ = $1;} + | T_ADDRESS {printf("string of T_ADDRESS in types is %s\n",$1);} {$$ = $1;} + | T_CHARACTER {printf("string of T_CHARACTER in types is %s\n",$1);} {$$ = $1;} + | T_BOOLEAN {printf("string of T_BOOLEAN in types is %s\n",$1);} {$$ = $1;} ; %% diff --git a/src/symbol_table.c b/src/symbol_table.c index 4b31b1e..7f8849b 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -650,7 +650,6 @@ TableNode *look_up(SymbolTable *table, char *x) { } 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"); @@ -673,87 +672,23 @@ 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 = entrie->next) { if (parant_scope == 0) { - + /*have to update*/ if (strcmp(entrie->theType->theName, + "function primitive") || + strcmp(entrie->theType->theName, + "array")) { + } fprintf(file_ptr, - "%-17s: %06d : : %-21d -> %-21s: %-28s\n", + "%-17s: %06d : : %-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"); + entrie->theType->theName, "Extra annotation"); } else { fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", entrie->theName, current_scope, parant_scope, - getType(entrie), - "Function"); + entrie->theType->theName, "Extra annotation"); } } -} if (table->Children_Scope != NULL) { ListOfTable *node = table->Children_Scope; for (; node != NULL; node = node->next) { @@ -766,6 +701,123 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { "----------------------\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 SymbolTable *getAncestor(SymbolTable *table) { if(table == NULL){