public static double GathersJsonData(LeagueStatement statement) { return ((statement is JsonBool || statement is JsonDouble || statement is JsonString) ? 1 : 0 + statement.getChildren().ToList().Sum(s => GathersJsonData(s))); }
private static double interpretNumIf(LeagueStatement statement) { LeagueStatement[] arguments = statement.getChildren(); if (interpretBool(arguments[0])) { return(interpretDouble(arguments[1])); } else { return(interpretDouble(arguments[2])); } }
private static bool interpretBool(LeagueStatement condition) { LeagueStatement[] arguments = condition.getChildren(); if (condition is BinaryBool) { return(interpretBinaryBool(condition)); } if (condition is Not) { return(!interpretBool(arguments[0])); } if (condition is JsonBool) { return(interpretJsonBool(condition as JsonBool)); } if (condition is StringEQ) { return(interpretStringVal(arguments[0] as StringVal).Equals(interpretStringVal(arguments[1] as StringVal))); } if (condition is IntEQ) { return(interpretDouble(arguments[0]) == interpretDouble(arguments[1])); } if (condition is GT) { return(interpretDouble(arguments[0]) > interpretDouble(arguments[1])); } if (condition is LT) { return(interpretDouble(arguments[0]) < interpretDouble(arguments[1])); } if (condition is True) { return(true); } if (condition is False) { return(false); } if (condition is BoolIf) { if (interpretBool(arguments[0])) { return(interpretBool(arguments[1])); } else { return(interpretBool(arguments[2])); } } throw new ArgumentException(); }
private static bool interpretBinaryBool(LeagueStatement statement) { LeagueStatement[] arguments = statement.getChildren(); if (statement is And) { return(interpretBool(arguments[0]) && interpretBool(arguments[1])); } if (statement is Or) { return(interpretBool(arguments[0]) || interpretBool(arguments[1])); } throw new System.ArgumentException(); }
public static void printStatement(LeagueStatement statement) { Console.Write("("); Console.Write(statement.GetType()); if (statement is Leaf) { Console.Write(" "); Console.Write((statement as Leaf).getValue()); } else { Console.Write("("); foreach (LeagueStatement s in statement.getChildren()) { printStatement(s); } Console.Write(")"); } Console.Write(")"); }
private static double interpretBinaryMathOp(LeagueStatement statement) { LeagueStatement[] arguments = statement.getChildren(); if (statement is Add) { return(interpretDouble(arguments[0]) + interpretDouble(arguments[1])); } if (statement is Subtract) { return(interpretDouble(arguments[0]) - interpretDouble(arguments[1])); } if (statement is Multiply) { return(interpretDouble(arguments[0]) * interpretDouble(arguments[1])); } if (statement is Divide) { return(interpretDouble(arguments[0]) / interpretDouble(arguments[1])); } return(0); // throw exception? }