Skip to content

Commit

Permalink
expr: Boolean logical operators
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Sep 3, 2024
1 parent 48cc473 commit b43c80a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions flamingo/grammar/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b43c80a

Please sign in to comment.