gecko-dev/js/js2/java/UnaryNode.java

62 строки
1.3 KiB
Java
Исходник Обычный вид История

1999-04-27 02:50:50 +04:00
class UnaryNode extends ExpressionNode {
UnaryNode(String aOp, ExpressionNode aChild)
{
child = aChild;
op = aOp;
}
String print(String indent)
{
StringBuffer result = new StringBuffer(indent);
result.append("UnaryNode ");
result.append(op);
result.append("\n");
indent += " ";
if (child == null) {
result.append(indent);
result.append("null\n");
}
else
result.append(child.print(indent));
return result.toString();
}
1999-05-28 23:00:48 +04:00
JSValue eval(Environment theEnv)
{
1999-05-28 23:00:48 +04:00
JSValue cV = child.eval(theEnv);
if (op == "+")
1999-05-28 23:00:48 +04:00
return cV.plus(theEnv);
else
if (op == "-")
1999-05-28 23:00:48 +04:00
return cV.minus(theEnv);
else
if (op == "~")
1999-05-28 23:00:48 +04:00
return cV.twiddle(theEnv);
else
if (op == "!")
1999-05-28 23:00:48 +04:00
return cV.bang(theEnv);
else
if (op == "typeof")
1999-05-28 23:00:48 +04:00
return cV.typeof(theEnv);
else {
System.out.println("missing unary op " + op);
1999-05-28 23:00:48 +04:00
return null;
}
}
1999-04-27 20:22:20 +04:00
String getOperator()
{
return op;
}
ExpressionNode getChild()
{
return child;
}
1999-04-27 02:50:50 +04:00
protected ExpressionNode child;
protected String op;
}