Skip to content

Commit 2d274aa

Browse files
Merge pull request #58 from Pip-Install-Party/officiablake-develop
fix output for file 5
2 parents b78bf65 + f5f79d8 commit 2d274aa

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

Output.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizzbuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizzbuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, Fizzbuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, Fizzbuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, Fizzbuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, Fizzbuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz
1+
2+
3+
4+
procedure main (void)
5+
{
6+
int counter;
7+
8+
counter = 100;
9+
10+
printf ("counter = %d\n", counter);
11+
}
12+

Tree/tree.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,34 +423,13 @@ bool Tree::isIndex(std::string headType) {
423423
}
424424

425425
Node* Tree::saveTree(std::ostringstream& buffer){
426+
426427
Node* root = nullptr;
427428
Node* prevNode = nullptr;
428429
std::string tempString;
429430
std::string content = buffer.str(); // Convert the buffer to a string
430-
431-
if (content.empty()) {
432-
return nullptr; // Handle empty buffer case
433-
}
434-
435-
const std::string targets[] = {" ---->", "|"}; // Substrings to replace
436-
for (const auto& target : targets) {
437-
std::size_t pos;
438-
while ((pos = content.find(target)) != std::string::npos) {
439-
content.replace(pos, target.length(), "~"); // Replace with a single space
440-
}
441-
}
442431

443-
// std::cout << "Reading characters: \n";
444-
// Print to check validity
445-
// for (char ch : content) {
446-
// std::cout << ch;
447-
// }
448-
449-
// if full interpreter is selected in main, do not output to file
450-
bool name = interpreterSelected;
451-
//std::cout << "value passed to tree is " << interpreterSelected << std::endl;
452-
453-
if (interpreterSelected == false) {
432+
if (interpreterSelected == false) {
454433

455434
//std::cout << "FULL INTERPRETER NOT SELECTED" << std::endl;
456435
// temporary output file for the AST to help with Interpreter
@@ -466,8 +445,17 @@ Node* Tree::saveTree(std::ostringstream& buffer){
466445
std::cerr << "Error opening file!" << std::endl; // Handle error if the file can't be opened
467446
}
468447
}
469-
else {
470-
//std::cout << "FULL INTERPRETER SELECTED" << std::endl;
448+
449+
if (content.empty()) {
450+
return nullptr; // Handle empty buffer case
451+
}
452+
453+
const std::string targets[] = {" ---->", "|"}; // Substrings to replace
454+
for (const auto& target : targets) {
455+
std::size_t pos;
456+
while ((pos = content.find(target)) != std::string::npos) {
457+
content.replace(pos, target.length(), "~"); // Replace with a single space
458+
}
471459
}
472460

473461
// Iterate through each character of the buffer

Tree/tree.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ class Tree {
4141
Tree(Token* head, Table* table, bool isInterpreter) {
4242

4343
interpreterSelected = isInterpreter;
44-
//std::cout << interpreterSelected << std::endl;
4544

4645
symbolTable = table;
4746
std::ostringstream ASTOutput;
4847
buildTree(head, nullptr, ASTOutput);
49-
root = saveTree(ASTOutput);
50-
printTree(saveTree(ASTOutput));
48+
if ( interpreterSelected ) {
49+
root = saveTree(ASTOutput);
50+
}
51+
//printTree(saveTree(ASTOutput));
5152
}
5253
Node* getHead() { return root; }
5354
~Tree();

0 commit comments

Comments
 (0)