/// <summary> /// Assign a value to an expression. /// </summary> /// <param name="expr">The assignment expressions</param> /// <returns></returns> public object VisitAssign(AssignExpr expr) { var ctx = expr.Ctx; var varExpr = expr.VarExp; var valueExpr = expr.ValueExp; var node = expr; var isDeclaration = expr.IsDeclaration; // CASE 1: Assign variable. a = 1 if (varExpr.IsNodeType(NodeTypes.SysVariable)) { AssignHelper.SetVariableValue(ctx, this, node, isDeclaration, varExpr, valueExpr); } // CASE 2: Assign member. // e.g. dictionary : user.name = 'kishore' // e.g. property on class: user.age = 20 else if (varExpr.IsNodeType(NodeTypes.SysMemberAccess)) { AssignHelper.SetMemberValue(ctx, this, node, varExpr, valueExpr); } // Case 3: Assign value to index: "users[0]" = <expression>; else if (varExpr.IsNodeType(NodeTypes.SysIndex)) { AssignHelper.SetIndexValue(ctx, this, node, varExpr, valueExpr); } return LObjects.Null; }
/// <summary> /// Creates a unary expression with symbol scope, context, script refernce set. /// </summary> /// <param name="name"></param> /// <param name="token"></param> /// <returns></returns> public static Expr Assign(bool declare, Expr left, Expr right, TokenData token) { var exp = new AssignExpr(); exp.IsDeclaration = declare; exp.VarExp = left; exp.ValueExp = right; SetupContext(exp, token); return exp; }
/// <summary> /// Visits the var statement tree. /// </summary> /// <param name="expr"></param> public object VisitAssign(AssignExpr expr) { _callBackOnNodeStart(expr); expr.VarExp.Visit(this); if (expr.ValueExp != null) expr.ValueExp.Visit(this); return null; }