private static int CombineValue(int valueX, int valueY, ArithCombine combine) { switch (combine) { case ArithCombine.Ignore: //Do nothing return(0); case ArithCombine.Add: return(valueX + valueY); case ArithCombine.Subtract: return(valueX - valueY); case ArithCombine.Multiply: return(valueX * valueY); case ArithCombine.Divide: return(valueX / valueY); case ArithCombine.Pow: return((int)Math.Pow(valueX, valueY)); case ArithCombine.Modulus: return(valueX % valueY); default: throw new ArgumentException($"No combine logic defined for combine type: {Enum.GetName(typeof(ArithCombine), combine)}"); } }
public static GrammarParseResult Combine(string rawText, GrammarParseResult x, GrammarParseResult y, BoolCombine isSuccessfulCombine = BoolCombine.Or, ArithCombine valueCombine = ArithCombine.Add, StrCombine outputCombine = StrCombine.Ignore) { GrammarParseResult combined = new GrammarParseResult(rawText); combined.IsSuccessful = CombineSuccessful(x.IsSuccessful, y.IsSuccessful, isSuccessfulCombine); combined.Value = CombineValue(x.Value, y.Value, valueCombine); combined.Output = CombineOutput(x.Output, y.Output, outputCombine); combined.Children.Add(x); combined.Children.Add(y); return(combined); }