private object ComputeAssign(BinaryExpr t, IEnvironment env, object rvalue) { ASTree l = t.Left; if (l is Name) { env.Put((l as Name).Text, rvalue); return(rvalue); } else if (l is PrimaryExpr) { PrimaryExpr p = l as PrimaryExpr; if (p.HasPostfix(0) && (p.Postfix(0) is Dot)) { p.Accept(this, env, 1); object tp = result; if (result is ErrorValue) { return(result); } if (tp is RavObject) { return(SetField(t, (tp as RavObject), (p.Postfix(0) as Dot), rvalue)); } } else if (p.HasPostfix(0) && (p.Postfix(0) is ArrayRef)) { p.Accept(this, env, 1); object a = result; if (result is ErrorValue) { return(result); } if (a is object[]) { ArrayRef aref = p.Postfix(0) as ArrayRef; aref.Index.Accept(this, env); if (result is ErrorValue) { return(result); } object index = result; if (index is int) { (a as object[])[(int)index] = rvalue; return(rvalue); } } result = new ErrorValue("bad array access", t); return(result); } } return(new ErrorValue("bad assignment", t)); }
private object EvalSubExpr(PrimaryExpr t, IEnvironment env, int nest) { if (t.HasPostfix(nest)) { object target = EvalSubExpr(t, env, nest + 1); t.Postfix(nest).Accept(this, env, target); return(result); } else { t.Operand.Accept(this, env); return(result); } }