diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2025-01-21 00:32:14 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2025-01-21 00:32:14 +0100 |
commit | 967dc36c30abbab9e2983568feab9bb514ab58df (patch) | |
tree | dd038d87758bfe17edba4c1ba5457b1ebbde9184 /src/evaluator.zig | |
parent | Parser: Add support for parenthesis grouping (diff) | |
download | interpreter-967dc36c30abbab9e2983568feab9bb514ab58df.tar.gz interpreter-967dc36c30abbab9e2983568feab9bb514ab58df.tar.bz2 interpreter-967dc36c30abbab9e2983568feab9bb514ab58df.zip |
Feature: Add support for NOT unary expression
Diffstat (limited to 'src/evaluator.zig')
-rw-r--r-- | src/evaluator.zig | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/evaluator.zig b/src/evaluator.zig index f35956a..c1997f3 100644 --- a/src/evaluator.zig +++ b/src/evaluator.zig @@ -144,6 +144,11 @@ pub const Evaluator = struct { if (x.addition) return try self.create_variable(.{ .NUMBER = lhs.NUMBER + rhs.NUMBER }); return try self.create_variable(.{ .NUMBER = lhs.NUMBER - rhs.NUMBER }); }, + .UNARY_EXPRESSION => |x| { + const val = try self.get_expression_value(x.expression) orelse return EvaluatorError.EvaluationError; + std.debug.assert(val.* == .BOOLEAN); + return try self.create_variable(.{ .BOOLEAN = !val.BOOLEAN }); + }, .EQUALITY_EXPRESSION => |x| { const lhs = try self.get_expression_value(x.lhs) orelse return EvaluatorError.EvaluationError; const rhs = try self.get_expression_value(x.rhs) orelse return EvaluatorError.EvaluationError; |