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))); }
public static void RunTests() { testData = new LeagueStatement[2]; testData[0] = new IntVal(5); testData[1] = new IntVal(10); RunMathTests(); }
public new bool Equals(LeagueStatement other) { if (other is IntVal) { return((other as IntVal).value == this.value); } else { return(false); } }
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 LeagueReturn interpret(LeagueStatement statement) { try { object ret = interpretDouble(statement); if (ret is double) { return(new ValidReturn(interpretDouble(statement))); } else { return(new TypeCheckException()); } } catch (Exception) { return(new RunTimeException()); } }
public static double interpretDouble(LeagueStatement statement) { if (statement is BinaryMathOp) { return(interpretBinaryMathOp(statement)); } if (statement is IntIf) { return(interpretNumIf(statement)); } if (statement is IntVal) { return((statement as IntVal).value); } if (statement is JsonDouble) { return(interpretJsonDouble(statement as JsonDouble)); } throw new 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? }
public new bool Equals(LeagueStatement other) { return(other is False); }
public static void print(LeagueStatement statement) { printStatement(statement); Console.WriteLine(""); }