예제 #1
0
        public static ForEachExpression Create(
            AphidExpressionContext context_aphidExpressionContext,
            AphidExpression collection_aphidExpression,
            List <AphidExpression> body_list,
            AphidExpression element_aphidExpression1,
            int value_i,
            int value_i1
            )
        {
            ForEachExpression forEachExpression = new ForEachExpression
                                                      (context_aphidExpressionContext, collection_aphidExpression,
                                                      body_list, element_aphidExpression1);

            ((AphidExpression)forEachExpression).Index  = value_i;
            ((AphidExpression)forEachExpression).Length = value_i1;
            return(forEachExpression);

            // TODO: Edit factory method of ForEachExpression
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
        private AphidObject InterpretForEachExpression(ForEachExpression expression)
        {
            var collection = InterpretExpression(expression.Collection) as AphidObject;
            var elements = collection.Value as List<AphidObject>;
            var elementId = (expression.Element as IdentifierExpression).Identifier;

            foreach (var element in elements)
            {
                EnterChildScope();
                _currentScope.Variables.Add(elementId, element);
                Interpret(expression.Body, false);

                if (LeaveChildScope(true) || _isBreaking)
                {
                    _isBreaking = false;
                    break;
                }
            }

            return null;
        }