Skip to content

Fixed tests 1-3, our output should match his, also comments added #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tree.x: main.o commentDFA.o tokenizer.o parser.o table.o tree.o
g++ -std=c++17 -g main.o commentDFA.o tokenizer.o parser.o table.o tree.o -o tree.x
tree.exe: main.o commentDFA.o tokenizer.o parser.o table.o tree.o
g++ -std=c++17 -g main.o commentDFA.o tokenizer.o parser.o table.o tree.o -o tree.exe

main.o: main.cpp commentDFA.h tokenizer.h parser.h testFiles.h
g++ -std=c++17 -g main.cpp -o main.o -c
Expand All @@ -20,4 +20,4 @@ tree.o: tree.cpp tree.h
g++ -std=c++17 -g tree.cpp -o tree.o -c

clean:
rm -f tree.x *.o *.txt
rm -f tree.exe *.o *.txt
63 changes: 44 additions & 19 deletions tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,45 +175,70 @@ Token* Tree::handleAssignment(Token* head) {
equationAsVec.push_back(head);
}


head = head->getSibling();

while(head->getValue() != ";" && (contains(equationOperators, head->getValue()) || head->getValue() != ";" || head->getValue() != "[" || head->getValue() != "]" || head->getType() == "IDENTIFIER" || head->getType() == "INTEGER" || head->getType() == "CHARACTER" || head->getType() == "STRING" || head->getType() == "DOUBLE_QUOTE")) {
// Check for function call (identifier with a L_PAREN)
if (isFunction(head->getValue())){
isCall = true;
}
if (head->getType() == "IDENTIFIER" && head->getSibling() != nullptr && head->getSibling()->getValue() == "(" && isCall) {
// Call to handleFunction since we encountered an identifier with a L_PAREN


//while(head != nullptr && head->getValue() != ";" && (contains(equationOperators, head->getValue()) || head->getValue() != ";" || head->getValue() != "[" || head->getValue() != "]" || head->getType() == "IDENTIFIER" || head->getType() == "INTEGER" || head->getType() == "CHARACTER" || head->getType() == "STRING" || head->getType() == "DOUBLE_QUOTE")) {
// Tokens processed until semicolon is reached
while(head != nullptr && head->getValue() != ";") {

// Process head as a function, since it is a function name followed by L_PAREN
if (isFunction(head->getValue()) && head->getSibling() && head->getSibling()->getValue() == "("){
equationAsVec.push_back(head); // Function's name
head = handleFunction(head, equationAsVec, isCall); // Process function parameters

// Checking if function has a '!'
if (prev != nullptr && prev->getValue() == "!") {
equationAsVec.push_back(prev);
prev = nullptr;
}

}
// Process head as an identifier followed by '('
else if (head->getType() == "IDENTIFIER" && head->getSibling() != nullptr && head->getSibling()->getValue() == "(" && isCall) {
auto temp = prev;
equationAsVec.push_back(head);
equationAsVec.push_back(head); // Add identifier
prev = head;
head = handleFunction(head, equationAsVec, isCall);
if(temp->getValue() == "!") {
equationAsVec.push_back(temp);
head = handleFunction(head, equationAsVec, isCall); // Process function

// Checking if function has a '!'
if (prev != nullptr && prev->getValue() == "!") {
equationAsVec.push_back(prev);
prev = nullptr;
}
}
else if (head->getValue() != "(" && head->getValue() != "!"){
// Checking for a '!' before function or expressions and set to prev until we process function or identifier
else if (head->getValue() == "!") {
prev = head;
}
// Checking for parentheses
else if (head->getValue() == "(" || head->getValue() == ")") {
equationAsVec.push_back(head);
}
// Any other operand pushed here
else if (head->getValue() != "(" && head->getValue() != "!"){
equationAsVec.push_back(head);

// Any '!' before operand
if (prev != nullptr && prev->getValue() == "!"){
equationAsVec.push_back(head);
equationAsVec.push_back(prev);
} else {
equationAsVec.push_back(head);
}
prev = nullptr;
}
}

// Go to next token or break if none left
if (head ->getSibling() != nullptr) {
prev = head;
head = head->getSibling();
}
else {
break;
}

}

// Convert infix to postfix
std::vector<Token*> postFix = infixToPostfix(equationAsVec, isCall);

//std::cout << "Size<: " << postFix.size() << std::endl;
for (int i = 0; i < postFix.size(); i++) {
std::string tokenValue = postFix.at(i)->getValue();
Expand Down