summary refs log tree commit diff
path: root/src/evaluator.zig
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-21 00:32:14 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-21 00:32:14 +0100
commit967dc36c30abbab9e2983568feab9bb514ab58df (patch)
treedd038d87758bfe17edba4c1ba5457b1ebbde9184 /src/evaluator.zig
parentParser: Add support for parenthesis grouping (diff)
downloadinterpreter-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.zig5
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;