Skip to content

Commit 668e3ce

Browse files
Merge pull request #8 from Pip-Install-Party/holdenkea-develop
2 parents 61c664c + f6a8771 commit 668e3ce

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tree.x: main.o commentDFA.o tokenizer.o parser.o table.o tree.o
2-
g++ -std=c++17 -g main.o commentDFA.o tokenizer.o parser.o table.o tree.o -o tree.x
1+
tree.exe: main.o commentDFA.o tokenizer.o parser.o table.o tree.o
2+
g++ -std=c++17 -g main.o commentDFA.o tokenizer.o parser.o table.o tree.o -o tree.exe
33

44
main.o: main.cpp commentDFA.h tokenizer.h parser.h testFiles.h
55
g++ -std=c++17 -g main.cpp -o main.o -c
@@ -20,4 +20,4 @@ tree.o: tree.cpp tree.h
2020
g++ -std=c++17 -g tree.cpp -o tree.o -c
2121

2222
clean:
23-
rm -f tree.x *.o *.txt
23+
rm -f tree.exe *.o *.txt

tree.cpp

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,45 +175,70 @@ Token* Tree::handleAssignment(Token* head) {
175175
equationAsVec.push_back(head);
176176
}
177177

178-
179178
head = head->getSibling();
180-
181-
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")) {
182-
// Check for function call (identifier with a L_PAREN)
183-
if (isFunction(head->getValue())){
184-
isCall = true;
185-
}
186-
if (head->getType() == "IDENTIFIER" && head->getSibling() != nullptr && head->getSibling()->getValue() == "(" && isCall) {
187-
// Call to handleFunction since we encountered an identifier with a L_PAREN
179+
180+
181+
//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")) {
182+
// Tokens processed until semicolon is reached
183+
while(head != nullptr && head->getValue() != ";") {
184+
185+
// Process head as a function, since it is a function name followed by L_PAREN
186+
if (isFunction(head->getValue()) && head->getSibling() && head->getSibling()->getValue() == "("){
187+
equationAsVec.push_back(head); // Function's name
188+
head = handleFunction(head, equationAsVec, isCall); // Process function parameters
189+
190+
// Checking if function has a '!'
191+
if (prev != nullptr && prev->getValue() == "!") {
192+
equationAsVec.push_back(prev);
193+
prev = nullptr;
194+
}
195+
196+
}
197+
// Process head as an identifier followed by '('
198+
else if (head->getType() == "IDENTIFIER" && head->getSibling() != nullptr && head->getSibling()->getValue() == "(" && isCall) {
188199
auto temp = prev;
189-
equationAsVec.push_back(head);
200+
equationAsVec.push_back(head); // Add identifier
190201
prev = head;
191-
head = handleFunction(head, equationAsVec, isCall);
192-
if(temp->getValue() == "!") {
193-
equationAsVec.push_back(temp);
202+
head = handleFunction(head, equationAsVec, isCall); // Process function
203+
204+
// Checking if function has a '!'
205+
if (prev != nullptr && prev->getValue() == "!") {
206+
equationAsVec.push_back(prev);
207+
prev = nullptr;
194208
}
195209
}
196-
else if (head->getValue() != "(" && head->getValue() != "!"){
210+
// Checking for a '!' before function or expressions and set to prev until we process function or identifier
211+
else if (head->getValue() == "!") {
212+
prev = head;
213+
}
214+
// Checking for parentheses
215+
else if (head->getValue() == "(" || head->getValue() == ")") {
216+
equationAsVec.push_back(head);
217+
}
218+
// Any other operand pushed here
219+
else if (head->getValue() != "(" && head->getValue() != "!"){
220+
equationAsVec.push_back(head);
221+
222+
// Any '!' before operand
197223
if (prev != nullptr && prev->getValue() == "!"){
198-
equationAsVec.push_back(head);
199224
equationAsVec.push_back(prev);
200-
} else {
201-
equationAsVec.push_back(head);
202-
}
225+
prev = nullptr;
226+
}
203227
}
204228

229+
// Go to next token or break if none left
205230
if (head ->getSibling() != nullptr) {
206231
prev = head;
207232
head = head->getSibling();
208233
}
209234
else {
210235
break;
211236
}
237+
212238
}
213239

214240
// Convert infix to postfix
215241
std::vector<Token*> postFix = infixToPostfix(equationAsVec, isCall);
216-
217242
//std::cout << "Size<: " << postFix.size() << std::endl;
218243
for (int i = 0; i < postFix.size(); i++) {
219244
std::string tokenValue = postFix.at(i)->getValue();

0 commit comments

Comments
 (0)