public void Translate(ActionSet actionSet)
        {
            if (DefinedVariable != null)
            {
                // Add the defined variable to the index assigner.
                actionSet.IndexAssigner.Add(actionSet.VarCollection, DefinedVariable, actionSet.IsGlobal, null);

                // Set the initial variable.
                if (actionSet.IndexAssigner[DefinedVariable] is IndexReference && DefinedVariable.InitialValue != null)
                {
                    actionSet.AddAction(((IndexReference)actionSet.IndexAssigner[DefinedVariable]).SetVariable(
                                            (Element)DefinedVariable.InitialValue.Parse(actionSet)
                                            ));
                }
            }
            else if (InitialVarSet != null)
            {
                InitialVarSet.Translate(actionSet);
            }

            WhileBuilder whileBuilder = new WhileBuilder(actionSet, Condition?.Parse(actionSet));

            whileBuilder.Setup();

            Block.Translate(actionSet);

            if (SetVariableAction != null)
            {
                SetVariableAction.Translate(actionSet);
            }

            whileBuilder.Finish();
        }
Пример #2
0
        public override void Translate(ActionSet actionSet)
        {
            if (DefinedVariable != null)
            {
                // Add the defined variable to the index assigner.
                actionSet.IndexAssigner.Add(actionSet.VarCollection, DefinedVariable, actionSet.IsGlobal, null);

                // Set the initial variable.
                if (actionSet.IndexAssigner[DefinedVariable] is IndexReference && DefinedVariable.InitialValue != null)
                {
                    actionSet.AddAction(((IndexReference)actionSet.IndexAssigner[DefinedVariable]).SetVariable(
                                            (Element)DefinedVariable.InitialValue.Parse(actionSet)
                                            ));
                }
            }
            else if (InitialVarSet != null)
            {
                InitialVarSet.Translate(actionSet);
            }

            // Get the condition.
            Element condition;

            if (Condition != null)
            {
                condition = (Element)Condition.Parse(actionSet);                    // User-define condition
            }
            else
            {
                condition = new V_True();  // No condition, just use true.
            }
            actionSet.AddAction(Element.Part <A_While>(condition));

            Block.Translate(actionSet.Indent());

            // Resolve continues.
            ResolveContinues(actionSet);

            if (SetVariableAction != null)
            {
                SetVariableAction.Translate(actionSet.Indent());
            }

            actionSet.AddAction(new A_End());

            // Resolve breaks.
            ResolveBreaks(actionSet);
        }