Infix evaluation operation now supported.
git-svn-id: https://svn.tlawal.org/svn/monkey@47 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
This commit is contained in:
parent
4b67c7d6e1
commit
a170eb4450
@ -56,6 +56,8 @@ func eval_prefix_expression(operator string, right object.Object) object.Object
|
||||
switch operator {
|
||||
case "!":
|
||||
return eval_bang_operator_expression(right)
|
||||
case "-":
|
||||
return eval_minus_prefix_operator_expression(right)
|
||||
|
||||
default:
|
||||
return NULL
|
||||
@ -77,3 +79,11 @@ func eval_bang_operator_expression(right object.Object) object.Object {
|
||||
return FALSE
|
||||
}
|
||||
}
|
||||
|
||||
func eval_minus_prefix_operator_expression(right object.Object) object.Object {
|
||||
if right.Type() != object.INTEGER_OBJECT{
|
||||
return NULL
|
||||
}
|
||||
value := right.(*object.Integer).Value
|
||||
return &object.Integer{Value: -value}
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ func TestEvalIntegerExpression(l_test *testing.T) {
|
||||
}{
|
||||
{"5", 5},
|
||||
{"10", 10},
|
||||
{"-10", -10},
|
||||
{"-5", -5},
|
||||
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user