public VariableElements ParseElements(ActionSet actionSet) { IndexReference var; Element target = null; Element[] index; if (Tree != null) { // Parse the tree. ExpressionTreeParseResult treeParseResult = Tree.ParseTree(actionSet, true); // Get the variable. var = (IndexReference)treeParseResult.ResultingVariable; // Get the target. target = (Element)treeParseResult.Target; // Get the index. index = treeParseResult.ResultingIndex; } else { // Get the variable. var = (IndexReference)actionSet.IndexAssigner[SetVariable.Calling]; // Get the index. index = Array.ConvertAll(SetVariable.Index, index => (Element)index.Parse(actionSet)); } return(new VariableElements(var, target, index)); }
public void Translate(ActionSet actionSet) { IGettable var; Element target = null; Element[] index; if (Tree != null) { ExpressionTreeParseResult treeParseResult = Tree.ParseTree(actionSet, true, true); var = treeParseResult.ResultingVariable; target = (Element)treeParseResult.Target; index = treeParseResult.ResultingIndex; } else { var = actionSet.IndexAssigner[SetVariable.Calling]; index = Array.ConvertAll(SetVariable.Index, index => (Element)index.Parse(actionSet)); } Element value = null; if (Value != null) { value = (Element)Value.Parse(actionSet); } Elements.Operation?modifyOperation = null; switch (Operation) { case "=": break; case "^=": modifyOperation = Elements.Operation.RaiseToPower; break; case "*=": modifyOperation = Elements.Operation.Multiply; break; case "/=": modifyOperation = Elements.Operation.Divide; break; case "%=": modifyOperation = Elements.Operation.Modulo; break; case "+=": modifyOperation = Elements.Operation.Add; break; case "-=": modifyOperation = Elements.Operation.Subtract; break; case "++": value = 1; modifyOperation = Elements.Operation.Add; break; case "--": value = 1; modifyOperation = Elements.Operation.Subtract; break; default: throw new Exception($"Unknown operation {Operation}."); } if (modifyOperation == null) { actionSet.AddAction(((IndexReference)var).SetVariable(value, target, index)); } else { actionSet.AddAction(((IndexReference)var).ModifyVariable((Elements.Operation)modifyOperation, value, target, index)); } }