Skip to content

Commit 1e82360

Browse files
Merge pull request #59 from Pip-Install-Party/officiablake-develop
resolve component five
2 parents ce2b196 + eb449b0 commit 1e82360

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
lines changed

Output.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

Tree/tree.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void Tree::printArrow(int spaces, std::ostringstream& ASTOutput){
2020

2121
// Prints the abstract syntax tree to the provided output stream
2222
void Tree::buildTree(Token* head, Token* prevToken, std::ostringstream& ASTOutput){
23-
2423
int lineNumber = 1;
2524
bool ignore = true;
2625

@@ -430,21 +429,22 @@ Node* Tree::saveTree(std::ostringstream& buffer){
430429
std::string content = buffer.str(); // Convert the buffer to a string
431430

432431
if (interpreterSelected == false) {
433-
434432
//std::cout << "FULL INTERPRETER NOT SELECTED" << std::endl;
435433
// temporary output file for the AST to help with Interpreter
436-
std::ofstream outFile("Output.txt"); // Open the file for writing
434+
// std::ofstream outFile("Output.txt"); // Open the file for writing
435+
std::string fileName = "Output.txt";
436+
std::ofstream outFile(fileName);
437437

438-
if (outFile.is_open()) { // Check if the file opened successfully
438+
//if (outFile.is_open()) { // Check if the file opened successfully
439439
for (char ch : content) {
440440
outFile << ch; // Write each character to the file
441441
}
442442
outFile.close(); // Close the file when done
443-
}
444-
else {
445-
std::cerr << "Error opening file!" << std::endl; // Handle error if the file can't be opened
446-
}
447-
}
443+
///}
444+
//else {
445+
// std::cerr << "Error opening file!" << std::endl; // Handle error if the file can't be opened
446+
// }
447+
}
448448

449449
if (content.empty()) {
450450
return nullptr; // Handle empty buffer case

Tree/tree.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ class Tree {
4545
symbolTable = table;
4646
std::ostringstream ASTOutput;
4747
buildTree(head, nullptr, ASTOutput);
48-
if ( interpreterSelected ) {
49-
root = saveTree(ASTOutput);
50-
}
48+
root = saveTree(ASTOutput);
49+
5150
//printTree(saveTree(ASTOutput));
5251
}
5352
Node* getHead() { return root; }

main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void abstractSyntaxTree(std::ifstream& testFile, std::ostringstream& outputFile,
148148
table->begin(parser->getHead());
149149

150150
bool isInterpreter = false;
151-
Tree* tree = new Tree(parser->getHead(), table, isInterpreter);
151+
Tree* tree = new Tree(parser->getHead(), table, false);
152152
}
153153

154154
void interpreter(std::ifstream& testFile, std::ostringstream& outputFile, int filenum) {
@@ -170,7 +170,7 @@ void interpreter(std::ifstream& testFile, std::ostringstream& outputFile, int fi
170170

171171

172172
bool isInterpreter = true;
173-
Tree* tree = new Tree(parser->getHead(), table, isInterpreter);
173+
Tree* tree = new Tree(parser->getHead(), table, true);
174174

175175
int mainLine = findMain(testFile);
176176

0 commit comments

Comments
 (0)