Exemplo n.º 1
0
 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)));
 }
Exemplo n.º 2
0
 public static void RunTests()
 {
     testData    = new LeagueStatement[2];
     testData[0] = new IntVal(5);
     testData[1] = new IntVal(10);
     RunMathTests();
 }
Exemplo n.º 3
0
 public new bool Equals(LeagueStatement other)
 {
     if (other is IntVal)
     {
         return((other as IntVal).value == this.value);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 private static double interpretNumIf(LeagueStatement statement)
 {
     LeagueStatement[] arguments = statement.getChildren();
     if (interpretBool(arguments[0]))
     {
         return(interpretDouble(arguments[1]));
     }
     else
     {
         return(interpretDouble(arguments[2]));
     }
 }
Exemplo n.º 5
0
 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();
 }
Exemplo n.º 6
0
 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();
 }
Exemplo n.º 7
0
 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());
     }
 }
Exemplo n.º 8
0
 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();
 }
Exemplo n.º 9
0
 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(")");
 }
Exemplo n.º 10
0
        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?
        }
Exemplo n.º 11
0
 public new bool Equals(LeagueStatement other)
 {
     return(other is False);
 }
Exemplo n.º 12
0
 public static void print(LeagueStatement statement)
 {
     printStatement(statement);
     Console.WriteLine("");
 }