/* Function: writeToFile() Description: Will write the contents of the symbol table to the output stream. */ void symbolTable::writeToScreen() { // variables bstItr bstItr; symTblItr symbolTableItr; Bst* currentBst; int scopeLevel = table.size() - 1; if (scopeLevel == -1) { std::cout << "Symbol table is empty!" << std::endl; } else { std::cout << "=== DISPLAYING SYMBOL TABLE ===" << std::endl; for (symbolTableItr = table.begin(); symbolTableItr != table.end(); symbolTableItr++) { currentBst = symbolTableItr->getBst(); for (int i = 0; i < symbolTableItr->getScopeLevel(); i++) { std::cout << "\t"; } std::cout << ">> Scope level " << symbolTableItr->getScopeLevel() << " in scope "; std::cout << symbolTableItr->getOuterScope() << "." << std::endl; if (currentBst->empty() ) { std::cout << "\tNo identifiers in this scope." << std::endl; } else { for (bstItr = currentBst->begin(); bstItr != currentBst->end(); bstItr++) { bstItr->second.displayIdentifierAttributes(symbolTableItr->getScopeLevel()); } } } std::cout << "=== END OF SYMBOL TABLE DISPLAY ===" << std::endl; } }
/* Function: writeToFile() Description: Will write the contents of the symbol table to a file that will be located in the "outputFiles" directory. */ void symbolTable::writeToFile() { // variables bstItr bstItr; symTblItr symbolTableItr; Bst* currentBst; std::ofstream outFile; outFile.open("../outputFiles/symbolTableContents.txt", std::ofstream::out); int scopeLevel = table.size() - 1; if (scopeLevel == -1) { outFile << "Symbol table is empty!" << std::endl; } else { outFile << "=== DISPLAYING SYMBOL TABLE ===" << std::endl; for (symbolTableItr = table.begin(); symbolTableItr != table.end(); symbolTableItr++) { currentBst = symbolTableItr->getBst(); for (int i = 0; i <= symbolTableItr->getScopeLevel(); i++) { outFile << "\t"; } outFile << ">> Scope level " << symbolTableItr->getScopeLevel() << " in scope "; outFile << symbolTableItr->getOuterScope() << "." << std::endl; if (currentBst->empty() ) { outFile << "\tNo identifiers in this scope." << std::endl; } else { for (bstItr = currentBst->begin(); bstItr != currentBst->end(); bstItr++) { for (int i = 0; i < symbolTableItr->getScopeLevel(); i++) { outFile << "\t"; } outFile << "\tVariable: " << bstItr->first << std::endl; for (int i = 0; i < symbolTableItr->getScopeLevel(); i++) { outFile << "\t"; } //outFile << "\tType: " << bstItr->second.getTypeStr() << std:: endl; } } } outFile << "=== END OF SYMBOL TABLE DISPLAY ===" << std::endl; } // file writing complete outFile.close(); }
/* Function: writeToFile() Description: Will write the contents of the symbol table to the output stream. */ void symbolTable::writeToScreen() { // variables bstItr bstItr; symTblItr symbolTableItr; Bst* currentBst; int scopeLevel = table.size() - 1; if(scopeLevel == -1){ std::cout << "Symbol table is empty!" << std::endl; } else { for (symbolTableItr = table.begin(); symbolTableItr != table.end(); symbolTableItr++) { currentBst = symbolTableItr->getBst(); for( int i = 0; i <= symbolTableItr->getScopeLevel(); i++ ){ std::cout << "\t"; } std::cout << "Scope Level " << symbolTableItr->getScopeLevel() << " in Scope "; std::cout << symbolTableItr->getOuterScope() << std::endl; if (currentBst->empty() ) { std::cout << "\tNo identifiers in this scope." << std::endl; } else { for (bstItr = currentBst->begin(); bstItr != currentBst->end(); bstItr++) { for( int i = 0; i < symbolTableItr->getScopeLevel(); i++ ){ std::cout << "\t"; } std::cout << "\tVariable: " << bstItr->first << std::endl; for( int i = 0; i < symbolTableItr->getScopeLevel(); i++ ){ std::cout << "\t"; } std::cout << "\tType: " << bstItr->second.getTypeStr() << std:: endl; } } } } }