예제 #1
0
파일: Running.cs 프로젝트: bamx23/ZInc
 public VarBool DoLogicalOperation(VarDouble a, VarDouble b, string operation)
 {
     switch (operation)
     {
         case "<":
             return new VarBool(a < b);
         case ">":
             return new VarBool(a > b);
         case "<=":
             return new VarBool(a <= b);
         case ">=":
             return new VarBool(a >= b);
         default:
             break;
     }
     return null;
 }
예제 #2
0
파일: Running.cs 프로젝트: bamx23/ZInc
 public VarDouble DoArifmeticOperation(VarDouble a, VarDouble b, string operation)
 {
     switch (operation)
     {
         case "+":
             return a + b;
         case "-":
             return a - b;
         case "*":
             return a * b;
         case "/":
             return a / b;
         case "%":
             return a % b;
         default:
             break;
     }
     return null;
 }
예제 #3
0
파일: Running.cs 프로젝트: bamx23/ZInc
 /// <summary>
 /// Этот метод приводит две переменные к одному типу, а потом колбасит их не по детски, и выполняет над ними операцию
 /// </summary>
 /// <param name="operands"> стек операндов текущего выражения</param>
 /// <param name="operation">А это кстати строка в которой лежит текущая операция, подход не супер, но лучше чем ничего</param>
 public void ConvertToOneType(Stack<VarObject> operands, string operation)
 {
     VarObject a, b;
     VarBool operBool1, operBool2;
     VarInt operInt1, operInt2;
     VarDouble operDouble1, operDouble2;
     VarString operString1, operString2;
     b = operands.Pop(); // Тут важен порядок поп(б) поп(а) не наоборот, иначе со стрингами лажа: задом наперед стринги получаются =)
     a = operands.Pop();
     switch (Math.Max(a.Type, b.Type))
     {
         case Constants.BOOL:
             operBool1 = new VarBool(a.ToBool());
             operBool2 = new VarBool(b.ToBool());
             operands.Push(DoOperation(operBool1, operBool2, operation));
             break;
         case Constants.INT:
             operInt1 = new VarInt(a.ToInt());
             operInt2 = new VarInt(b.ToInt());
             operands.Push(DoOperation(operInt1, operInt2, operation));
             break;
         case Constants.DOUBLE:
             operDouble1 = new VarDouble(a.ToDouble());
             operDouble2 = new VarDouble(b.ToDouble());
             operands.Push(DoOperation(operDouble1, operDouble2, operation));
             break;
         case Constants.STRING:
             operString1 = new VarString(a.ToStr());
             operString2 = new VarString(b.ToStr());
             operands.Push(DoOperation(operString1, operString2, operation));
             break;
         default: // ololo Oshibka detected what to do now???? todolist!!!! oshibka oshibka( tut proishodit beg po krugu i kriki o pomoshi)
             break;
     }
 }
예제 #4
0
파일: Running.cs 프로젝트: bamx23/ZInc
 public VarObject DoOperation(VarDouble a, VarDouble b, string operation)
 {
     if (operation == "+" || operation == "-" || operation == "*" || operation == "/" || operation == "%")
         return DoArifmeticOperation(a, b, operation);
     else
         return DoLogicalOperation(a, b, operation);
 }
예제 #5
0
파일: Functions.cs 프로젝트: semens/ZInc
 public override int Do(ref int Line)
 {
     try
     {
         VarObject V;
         switch (param[0])
         {
             case "int":
                 V = new VarInt();
                 break;
             case "double":
                 V = new VarDouble();
                 break;
             case "string":
                 V = new VarString();
                 break;
             case "bool":
                 V = new VarBool();
                 break;
             default:
                 V = new VarObject();
                 break;
         }
         Prog.Var.Add(V);
         return base.Do(ref Line);
     }
     catch (Exception e)
     {
         return Except(e);
     }
 }