evalBinaryExpression method
dynamic
evalBinaryExpression(
- BinaryExpression expression,
- Map<
String, dynamic> context, { - void onValueAssigned(
- String key,
- dynamic value
inherited
Implementation
@protected
dynamic evalBinaryExpression(
BinaryExpression expression,
Map<String, dynamic> context, {
void Function(String key, dynamic value)? onValueAssigned,
}) {
dynamic result;
final left = eval(expression.left, context);
dynamic right() => eval(expression.right, context);
switch (expression.operator) {
case '=':
final leftVar = expression.left.toString();
result = right();
context[leftVar] = result;
if (onValueAssigned != null) {
onValueAssigned(leftVar, result);
}
break;
case '||':
result = left || right();
break;
case '&&':
result = left && right();
break;
case '|':
result = left | right();
break;
case '^':
result = left ^ right();
break;
case '&':
result = left & right();
break;
case '==':
result = left == right();
break;
case '!=':
result = left != right();
break;
case '<=':
result = left <= right();
break;
case '>=':
result = left >= right();
break;
case '<':
result = left < right();
break;
case '>':
result = left > right();
break;
case '<<':
result = left << right();
break;
case '>>':
result = left >> right();
break;
case '+':
final r = right();
result = left + r;
break;
case '-':
result = left - right();
break;
case '*':
result = left * right();
break;
case '/':
result = left / right();
break;
case '%':
result = left % right();
break;
case '??':
result = left ?? right();
break;
default:
throw ArgumentError(
'Unknown operator ${expression.operator} in expression',
);
}
return result;
}