예제 #1
0
        public Value Evaluate(Environment environment)
        {
            var value = expression.Evaluate(environment);

            if (value.IsList() || value.IsSet())
            {
                var   list   = value.AsList().GetValue();
                Value result = ValueNull.NULL;
                for (var i = 0; i < identifiers.Count; i++)
                {
                    if (!environment.IsDefined(identifiers[i]))
                    {
                        throw new ControlErrorException(new ValueString("ERROR"), "Variable '" + identifiers[i] + "' is not defined", pos);
                    }
                    if (i < list.Count)
                    {
                        environment.Set(identifiers[i], list[i]);
                        result = list[i];
                    }
                    else
                    {
                        environment.Set(identifiers[i], ValueNull.NULL);
                        result = ValueNull.NULL;
                    }
                }
                return(result);
            }
            throw new ControlErrorException(new ValueString("ERROR"), "Destructuring assign expected list or set but got " + value.Type(), pos);
        }
예제 #2
0
 public Value Evaluate(Environment environment)
 {
     if (!environment.IsDefined(identifier))
     {
         throw new ControlErrorException(new ValueString("ERROR"), "Variable '" + identifier + "' is not defined", pos);
     }
     environment.Set(identifier, expression.Evaluate(environment));
     return(environment.Get(identifier, pos));
 }