From b43c80a10b7c00bf4436ce3054b36324809598c6 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Tue, 3 Sep 2024 11:43:57 +0200 Subject: [PATCH] expr: Boolean logical operators --- flamingo/grammar/expr.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/flamingo/grammar/expr.h b/flamingo/grammar/expr.h index d5df411..94aae6d 100644 --- a/flamingo/grammar/expr.h +++ b/flamingo/grammar/expr.h @@ -164,6 +164,26 @@ static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t** } if (kind == FLAMINGO_VAL_KIND_BOOL) { + // Logical operators. + + if (strncmp(operator, "&&", operator_size) == 0) { + (*val)->kind = FLAMINGO_VAL_KIND_BOOL; + (*val)->boolean.val = left_val->boolean.val && right_val->boolean.val; + goto done; + } + + if (strncmp(operator, "||", operator_size) == 0) { + (*val)->kind = FLAMINGO_VAL_KIND_BOOL; + (*val)->boolean.val = left_val->boolean.val || right_val->boolean.val; + goto done; + } + + if (strncmp(operator, "^^", operator_size) == 0) { + (*val)->kind = FLAMINGO_VAL_KIND_BOOL; + (*val)->boolean.val = (!!left_val->boolean.val) ^ (!!right_val->boolean.val); + goto done; + } + // Comparisons. if (strncmp(operator, "==", operator_size) == 0) {