1999-05-20 04:14:26 +04:00
|
|
|
class LogicalNode extends BinaryNode {
|
|
|
|
|
|
|
|
LogicalNode(String aOp, ExpressionNode aLeft, ExpressionNode aRight)
|
|
|
|
{
|
|
|
|
super(aOp, aLeft, aRight);
|
|
|
|
}
|
|
|
|
|
1999-05-28 23:00:48 +04:00
|
|
|
JSValue eval(Environment theEnv)
|
1999-05-20 04:14:26 +04:00
|
|
|
{
|
1999-05-28 23:00:48 +04:00
|
|
|
JSBoolean b = left.eval(theEnv).toJSBoolean(theEnv);
|
1999-05-20 04:14:26 +04:00
|
|
|
if (op == "&&") {
|
1999-05-21 01:16:11 +04:00
|
|
|
if (b.isFalse())
|
1999-05-28 23:00:48 +04:00
|
|
|
return b;
|
1999-05-20 04:14:26 +04:00
|
|
|
else {
|
1999-05-28 23:00:48 +04:00
|
|
|
b = right.eval(theEnv).toJSBoolean(theEnv);
|
1999-05-21 01:16:11 +04:00
|
|
|
if (b.isFalse())
|
1999-05-28 23:00:48 +04:00
|
|
|
return b;
|
1999-05-20 04:14:26 +04:00
|
|
|
else
|
1999-05-28 23:00:48 +04:00
|
|
|
return JSBoolean.JSTrue;
|
1999-05-20 04:14:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (op == "||") {
|
1999-05-21 01:16:11 +04:00
|
|
|
if (b.isTrue())
|
1999-05-28 23:00:48 +04:00
|
|
|
return b;
|
1999-05-20 04:14:26 +04:00
|
|
|
else {
|
1999-05-28 23:00:48 +04:00
|
|
|
b = right.eval(theEnv).toJSBoolean(theEnv);
|
1999-05-21 01:16:11 +04:00
|
|
|
if (b.isTrue())
|
1999-05-28 23:00:48 +04:00
|
|
|
return b;
|
1999-05-20 04:14:26 +04:00
|
|
|
else
|
1999-05-28 23:00:48 +04:00
|
|
|
return JSBoolean.JSFalse;
|
1999-05-20 04:14:26 +04:00
|
|
|
}
|
|
|
|
}
|
1999-05-28 23:00:48 +04:00
|
|
|
else {
|
1999-05-20 04:14:26 +04:00
|
|
|
System.out.println("missing logical op " + op);
|
1999-05-28 23:00:48 +04:00
|
|
|
return null;
|
|
|
|
}
|
1999-05-20 04:14:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|