diff --git a/evaluator/evaluator.go b/evaluator/evaluator.go index 134e434..57a0bef 100644 --- a/evaluator/evaluator.go +++ b/evaluator/evaluator.go @@ -150,6 +150,18 @@ func evalIntegerInfixExpression( case token.DIV: result := new(big.Int).Div(&leftVal, &rightVal) return &object.Integer{Value: *result} + case token.GREATER_THAN: + isGreater := leftVal.Cmp(&rightVal) == 1 + return nativeBoolToBooleanObject(isGreater) + case token.LESS_THAN: + isLess := leftVal.Cmp(&rightVal) == -1 + return nativeBoolToBooleanObject(isLess) + case token.EQUAL: + isEqual := leftVal.Cmp(&rightVal) == 0 + return nativeBoolToBooleanObject(isEqual) + case token.NOT_EQUAL: + isNotEqual := leftVal.Cmp(&rightVal) != 0 + return nativeBoolToBooleanObject(isNotEqual) } } diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index 9c97c88..12d8a28 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -36,6 +36,14 @@ func Test_EvalBooleanExpression(t *testing.T) { }{ {"true", true}, {"false", false}, + {"1 > 2", false}, + {"2 > 1", true}, + {"2 < 3", true}, + {"2 < 1", false}, + {"3 == 3", true}, + {"3 == 5", false}, + {"3 != 4", true}, + {"5 != 5", false}, } for _, tt := range tests {