Added ternary operator, resolved #46

This commit is contained in:
2023-01-14 10:24:15 +00:00
parent 4b60d65203
commit ae1dc5841e
11 changed files with 140 additions and 9 deletions

View File

@@ -29,6 +29,12 @@ void freeASTNodeCustom(ASTNode* node, bool freeSelf) {
freeASTNode(node->binary.right);
break;
case AST_NODE_TERNARY:
freeASTNode(node->ternary.condition);
freeASTNode(node->ternary.thenPath);
freeASTNode(node->ternary.elsePath);
break;
case AST_NODE_GROUPING:
freeASTNode(node->grouping.child);
break;
@@ -169,6 +175,17 @@ void emitASTNodeBinary(ASTNode** nodeHandle, ASTNode* rhs, Opcode opcode) {
*nodeHandle = tmp;
}
void emitASTNodeTernary(ASTNode** nodeHandle, ASTNode* condition, ASTNode* thenPath, ASTNode* elsePath) {
ASTNode* tmp = ALLOCATE(ASTNode, 1);
tmp->type = AST_NODE_TERNARY;
tmp->ternary.condition = condition;
tmp->ternary.thenPath = thenPath;
tmp->ternary.elsePath = elsePath;
*nodeHandle = tmp;
}
void emitASTNodeGrouping(ASTNode** nodeHandle) {
ASTNode* tmp = ALLOCATE(ASTNode, 1);