Increment and decrement operators work

This commit is contained in:
2022-08-21 00:23:01 +01:00
parent c64d451287
commit b385b461e0
8 changed files with 185 additions and 26 deletions

View File

@@ -73,6 +73,11 @@ void freeNode(Node* node) {
freeNode(node->path.thenPath);
freeNode(node->path.elsePath);
break;
case NODE_INCREMENT_PREFIX:
case NODE_INCREMENT_POSTFIX:
freeLiteral(node->increment.identifier);
break;
}
}
@@ -179,6 +184,26 @@ void emitNodePath(Node** nodeHandle, NodeType type, Node* preClause, Node* postC
*nodeHandle = tmp;
}
void emiteNodePrefixIncrement(Node** nodeHandle, Literal identifier, int increment) {
Node* tmp = ALLOCATE(Node, 1);
tmp->type = NODE_INCREMENT_PREFIX;
tmp->increment.identifier = identifier;
tmp->increment.increment = increment;
*nodeHandle = tmp;
}
void emiteNodePostfixIncrement(Node** nodeHandle, Literal identifier, int increment) {
Node* tmp = ALLOCATE(Node, 1);
tmp->type = NODE_INCREMENT_POSTFIX;
tmp->increment.identifier = identifier;
tmp->increment.increment = increment;
*nodeHandle = tmp;
}
void printNode(Node* node) {
if (node == NULL) {
return;
@@ -271,6 +296,11 @@ void printNode(Node* node) {
printf(")");
break;
// case NODE_INCREMENT_PREFIX:
// case NODE_INCREMENT_POSTFIX:
// //TODO
// break;
default:
printf("[internal] unkown node type in printNode: %d\n", node->type);
}