1999-04-26 22:50:50 +00:00
|
|
|
class BinaryNode extends ExpressionNode {
|
|
|
|
|
|
|
|
BinaryNode(String aOp, ExpressionNode aLeft, ExpressionNode aRight)
|
|
|
|
{
|
|
|
|
left = aLeft;
|
|
|
|
right = aRight;
|
|
|
|
op = aOp;
|
|
|
|
}
|
1999-05-07 22:07:22 +00:00
|
|
|
|
1999-05-28 19:00:48 +00:00
|
|
|
JSReference evalLHS(Environment theEnv)
|
1999-05-25 21:49:40 +00:00
|
|
|
{
|
1999-05-26 01:01:07 +00:00
|
|
|
if (op == ".") {
|
1999-05-28 19:00:48 +00:00
|
|
|
JSValue lV = left.eval(theEnv);
|
|
|
|
JSString id;
|
1999-05-26 01:01:07 +00:00
|
|
|
if (right instanceof JSIdentifier)
|
1999-05-28 19:00:48 +00:00
|
|
|
id = (JSString)right;
|
1999-05-26 01:01:07 +00:00
|
|
|
else
|
1999-05-28 19:00:48 +00:00
|
|
|
id = right.eval(theEnv).toJSString(theEnv);
|
|
|
|
return new JSReference(lV, id);
|
1999-05-26 01:01:07 +00:00
|
|
|
}
|
1999-05-25 21:49:40 +00:00
|
|
|
else
|
1999-05-26 01:01:07 +00:00
|
|
|
throw new RuntimeException("bad lValue operator " + op);
|
1999-05-25 21:49:40 +00:00
|
|
|
}
|
|
|
|
|
1999-05-28 19:00:48 +00:00
|
|
|
JSValue eval(Environment theEnv)
|
1999-05-07 22:07:22 +00:00
|
|
|
{
|
1999-05-28 19:00:48 +00:00
|
|
|
JSValue lV = left.eval(theEnv);
|
|
|
|
JSValue rV = right.eval(theEnv);
|
1999-05-25 21:49:40 +00:00
|
|
|
|
|
|
|
if (op == ".")
|
1999-05-28 19:00:48 +00:00
|
|
|
return lV.getProp(theEnv, rV.toJSString(theEnv));
|
1999-06-11 00:21:26 +00:00
|
|
|
else
|
|
|
|
if (op == "()")
|
|
|
|
return lV.call(theEnv, rV);
|
|
|
|
else
|
|
|
|
if (op == ",")
|
|
|
|
return JSValueList.buildList(lV, rV);
|
1999-05-28 19:00:48 +00:00
|
|
|
else {
|
1999-05-25 21:49:40 +00:00
|
|
|
System.out.println("missing binary op " + op);
|
1999-05-28 19:00:48 +00:00
|
|
|
return null;
|
|
|
|
}
|
1999-05-25 21:49:40 +00:00
|
|
|
|
1999-05-07 22:07:22 +00:00
|
|
|
}
|
1999-04-26 22:50:50 +00:00
|
|
|
|
|
|
|
String print(String indent)
|
|
|
|
{
|
|
|
|
StringBuffer result = new StringBuffer(indent);
|
|
|
|
result.append(getClass().toString());
|
|
|
|
result.append(" ");
|
|
|
|
result.append(op);
|
|
|
|
result.append("\n");
|
|
|
|
indent += " ";
|
|
|
|
if (left == null) {
|
|
|
|
result.append(indent);
|
|
|
|
result.append("null\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result.append(left.print(indent));
|
|
|
|
if (right == null) {
|
|
|
|
result.append(indent);
|
|
|
|
result.append("null\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result.append(right.print(indent));
|
|
|
|
return result.toString();
|
1999-05-07 22:07:22 +00:00
|
|
|
}
|
1999-04-26 22:50:50 +00:00
|
|
|
|
|
|
|
protected ExpressionNode left;
|
|
|
|
protected ExpressionNode right;
|
|
|
|
protected String op;
|
|
|
|
|
|
|
|
}
|