public void Translate(ActionSet actionSet) { // Add the if action. A_If newIf = Element.Part <A_If>(Expression.Parse(actionSet)); newIf.Comment = Comment; actionSet.AddAction(newIf); // Translate the if block. Block.Translate(actionSet.Indent()); // Add the else-ifs. for (int i = 0; i < ElseIfs.Length; i++) { // Add the else-if action. actionSet.AddAction(Element.Part <A_ElseIf>(ElseIfs[i].Expression.Parse(actionSet))); // Translate the else-if block. ElseIfs[i].Block.Translate(actionSet.Indent()); } // If there is an else block, translate it. if (ElseBlock != null) { actionSet.AddAction(new A_Else()); ElseBlock.Translate(actionSet.Indent()); } // Add the end of the if. actionSet.AddAction(new A_End()); }
public override void Translate(ActionSet actionSet) { int actionCountPreCondition = actionSet.ActionCount; Element condition = (Element)Condition.Parse(actionSet); bool actionsAdded = actionSet.ActionCount > actionCountPreCondition; if (!actionsAdded) { // Create a normal while loop. actionSet.AddAction(Element.Part <A_While>(condition)); // Translate the block. Block.Translate(actionSet.Indent()); // Resolve continues. ResolveContinues(actionSet); // Cap the block. actionSet.AddAction(new A_End()); // Resolve breaks. ResolveBreaks(actionSet); } else { // The while condition requires actions to get the value. actionSet.ActionList.Insert(actionCountPreCondition, new ALAction(Element.Part <A_While>(new V_True()))); SkipStartMarker whileEndSkip = new SkipStartMarker(actionSet, condition); actionSet.Indent().AddAction(whileEndSkip); // Translate the block. Block.Translate(actionSet.Indent()); // Resolve continues. ResolveContinues(actionSet); // Cap the block. actionSet.AddAction(new A_End()); // Skip to the end when the condition is false. SkipEndMarker whileEnd = new SkipEndMarker(); whileEndSkip.SetEndMarker(whileEnd); actionSet.AddAction(whileEnd); // Resolve breaks. ResolveBreaks(actionSet); } }
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); }
public override void Translate(ActionSet actionSet) { WorkshopVariable variable; Element target; Element start; // Existing variable being used in for. if (VariableResolve != null) { VariableElements elements = VariableResolve.ParseElements(actionSet); variable = elements.IndexReference.WorkshopVariable; target = elements.Target; start = (Element)InitialResolveValue?.Parse(actionSet) ?? new V_Number(0); } // New variable being use in for. else { actionSet.IndexAssigner.Add(actionSet.VarCollection, DefinedVariable, actionSet.IsGlobal, null); variable = ((IndexReference)actionSet.IndexAssigner[DefinedVariable]).WorkshopVariable; target = new V_EventPlayer(); start = (Element)DefinedVariable.InitialValue?.Parse(actionSet) ?? new V_Number(0); } Element stop = (Element)Stop.Parse(actionSet); Element step = (Element)Step.Parse(actionSet); // Global if (variable.IsGlobal) { actionSet.AddAction(Element.Part <A_ForGlobalVariable>( variable, start, stop, step )); } // Player else { actionSet.AddAction(Element.Part <A_ForPlayerVariable>( target, variable, start, stop, step )); } // Translate the block. Block.Translate(actionSet.Indent()); // Resolve continues. ResolveContinues(actionSet); // Cap the for. actionSet.AddAction(new A_End()); // Resolve breaks. ResolveBreaks(actionSet); }
public override void Translate(ActionSet actionSet) { ForeachBuilder foreachBuilder = new ForeachBuilder(actionSet, Array.Parse(actionSet), actionSet.IsRecursive); // Add the foreach value to the assigner. actionSet.IndexAssigner.Add(ForeachVar, foreachBuilder.IndexValue); // Translate the block. Block.Translate(actionSet.Indent()); // Resolve continues. ResolveContinues(actionSet); // Finish the foreach. foreachBuilder.Finish(); // Resolve breaks. ResolveBreaks(actionSet); }