Skip to content

Commit 3962813

Browse files
committed
added/modified logic for printTree
1 parent 4d94567 commit 3962813

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tree.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ void Tree::printTree(Token* head, Token* prevToken){
3333
head = handleAssignment(head);
3434
prevToken = nullptr;
3535

36+
} else if (head->getValue() == "printf"){
37+
ignore = true;
38+
std::cout << "PRINTF";
39+
while (head->getSibling() != nullptr) {
40+
head = head->getSibling();
41+
if (head->getType() != "L_PAREN" && head->getType() != "R_PAREN" && head->getType() != "DOUBLE_QUOTE" && head->getType() != "COMMA" && head->getType() != "SEMICOLON") {
42+
std::cout << " ----> ";
43+
std::cout << head->getValue();
44+
}
45+
}
46+
std::cout << "\n|\n|\n|\n|\nv\n";
47+
prevToken = nullptr;
48+
3649
} else if (head->getValue() == "for"){
3750
short forCount = 0;
3851
ignore = false;
@@ -41,12 +54,14 @@ void Tree::printTree(Token* head, Token* prevToken){
4154
head = head->getSibling();
4255
head = handleAssignment(head);
4356
prevToken = nullptr;
44-
std::cout << "\n|\n|\n|\n|\nv\n ";
57+
if (forCount+1 < 3) {
58+
std::cout << "\n|\n|\n|\n|\nv\n ";
59+
}
4560
forCount++;
4661
}
4762

4863
}else if (contains(varTypes, prevToken->getValue())) {
49-
ignore = false;
64+
ignore = true; // this was false but i think should be true
5065
std::cout << "DECLARATION";
5166
if (head->getSibling() != nullptr && head->getSibling()->getValue() == ",") {
5267
while(head->getSibling() != nullptr) {
@@ -55,6 +70,7 @@ void Tree::printTree(Token* head, Token* prevToken){
5570
std::cout << "\n|\n|\n|\n|\nv\nDECLARATION";
5671
}
5772
}
73+
std::cout << "\n|\n|\n|\n|\nv\n";
5874
}
5975
} else if (head->getType() == "IDENTIFIER") {
6076
if (head->getSibling() != nullptr && head->getSibling()->getValue() == "=") {
@@ -65,7 +81,7 @@ void Tree::printTree(Token* head, Token* prevToken){
6581
prevToken = nullptr;
6682
}
6783
} else if (head->getSibling() == nullptr && head->getChild() != nullptr && head->getValue() == ";"){
68-
std::cout << "\n|\n|\n|\n|\nv\n ";
84+
std::cout << "\n|\n|\n|\n|\nv\n";
6985
}
7086
if (head->getSibling() != nullptr) {
7187
if (!ignore){
@@ -75,7 +91,7 @@ void Tree::printTree(Token* head, Token* prevToken){
7591
return printTree(head->getSibling(), head);
7692
} else if (head->getChild() != nullptr) {
7793
if (!ignore) {
78-
std::cout << "\n|\n|\n|\n|\nv\n ";
94+
std::cout << "\n|\n|\n|\n|\nv\n";
7995
}
8096
return printTree(head->getChild(), head);
8197
}

0 commit comments

Comments
 (0)