Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
preop and postop
Browse files Browse the repository at this point in the history
  • Loading branch information
Erzis900 committed Aug 31, 2020
1 parent d799804 commit 84635d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/interpreter/nodes/PostOpNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,21 @@ Symbol PostOpNode::sematicCheck(Symbol param) {
}

Symbol PostOpNode::execute(Symbol sym) {
for (int i = 0; i < children.size(); i++) {
children[i]->execute();
Symbol lhs = children[0]->execute();
int result = 0;

if(value == "++") {
result = get<int>(lhs.value)++;
SymbolTable::getInstance()->update(lhs);
}
else if(value == "--") {
result = get<int>(lhs.value)--;
SymbolTable::getInstance()->update(lhs);
}
else {
ErrorHandler::error(value + " operator not found");
return Symbol::ERROR();
}

return Symbol::EMPTY();
return Symbol::EXPRESSION("int", result);
}
20 changes: 17 additions & 3 deletions src/interpreter/nodes/PreOpNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@ Symbol PreOpNode::sematicCheck(Symbol param) {
}

Symbol PreOpNode::execute(Symbol sym) {
for (int i = 0; i < children.size(); i++) {
children[i]->execute();
Symbol lhs = children[0]->execute();
int result = 0;

if(value == "!") return Symbol::EXPRESSION("bool", !get<int>(lhs.value));
else if(value == "~") result = ~get<int>(lhs.value);
else if(value == "++") {
result = ++get<int>(lhs.value);
SymbolTable::getInstance()->update(lhs);
}
else if(value == "--") {
result = --get<int>(lhs.value);
SymbolTable::getInstance()->update(lhs);
}
else {
ErrorHandler::error(value + " operator not found");
return Symbol::ERROR();
}

return Symbol::EMPTY();
return Symbol::EXPRESSION("int", result);
}

0 comments on commit 84635d9

Please sign in to comment.