1999-04-26 22:50:50 +00: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 19:00:48 +00:00
|
|
|
JSValue eval(Environment theEnv)
|
1999-05-25 21:49:40 +00:00
|
|
|
{
|
1999-05-28 19:00:48 +00:00
|
|
|
JSValue cV = child.eval(theEnv);
|
1999-05-25 21:49:40 +00:00
|
|
|
|
|
|
|
if (op == "+")
|
1999-05-28 19:00:48 +00:00
|
|
|
return cV.plus(theEnv);
|
1999-05-25 21:49:40 +00:00
|
|
|
else
|
|
|
|
if (op == "-")
|
1999-05-28 19:00:48 +00:00
|
|
|
return cV.minus(theEnv);
|
1999-05-25 21:49:40 +00:00
|
|
|
else
|
|
|
|
if (op == "~")
|
1999-05-28 19:00:48 +00:00
|
|
|
return cV.twiddle(theEnv);
|
1999-05-25 21:49:40 +00:00
|
|
|
else
|
|
|
|
if (op == "!")
|
1999-05-28 19:00:48 +00:00
|
|
|
return cV.bang(theEnv);
|
1999-05-25 21:49:40 +00:00
|
|
|
else
|
|
|
|
if (op == "typeof")
|
1999-05-28 19:00:48 +00:00
|
|
|
return cV.typeof(theEnv);
|
|
|
|
else {
|
1999-05-25 21:49:40 +00:00
|
|
|
System.out.println("missing unary op " + op);
|
1999-05-28 19:00:48 +00:00
|
|
|
return null;
|
|
|
|
}
|
1999-05-25 21:49:40 +00:00
|
|
|
}
|
|
|
|
|
1999-04-27 16:22:20 +00:00
|
|
|
String getOperator()
|
|
|
|
{
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpressionNode getChild()
|
|
|
|
{
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
1999-04-26 22:50:50 +00:00
|
|
|
protected ExpressionNode child;
|
|
|
|
protected String op;
|
|
|
|
|
|
|
|
}
|