Esempio n. 1
0
 } // Changes
 /// <summary>
 /// Самым непосредственным образом парсит строку записанную польской записью =)
 /// </summary>
 /// <param name="name">собственно сама строка, которую надо разбрать</param>
 /// <returns></returns>
 public VarObject ParseString(string name)
 {
     Stack<VarObject> operands = new Stack<VarObject>();
     VarObject tempVar = new VarObject();
     string[] literal = name.Split(' ');
     if (name[0] == '(') // Changes
     {
         name = name.Remove(0, 1);
         name = name.Remove(name.Length - 1, 1);
     } // Changes
     foreach (string s in literal)
     {
         if (s[0] == 'V' || s[0] == 'P' || s[0] == 'T')
         {
             try
             {
                 operands.Push(GetVar(s));
             }
             catch (Exception e)
             {
             }
         }
         else
         {
             if (s == "+" || s == "-" || s == "*" || s == "/" ||
                 s == "==" || s == "<" || s == "<=" || s == ">" || s == ">=")
                 ConvertToOneType(operands, s);
             else
             {
                 if (s[0] == '\'' && s[s.Length - 1] == '\'')
                 {
                     operands.Push(new VarString(s.Trim('\'', '\'')));
                     continue;
                 }
                 if (s[0] == '\"' && s[s.Length - 1] == '\"')
                 {
                     operands.Push(new VarString(s.Trim('\"', '\"')));
                     continue;
                 }
                 if (TryParseStandartFunc(s, ref tempVar))  // Changes
                 {
                     operands.Push(tempVar);
                     continue;
                 }  // Changes
                 if (s == "true" || s == "false")
                 {
                     operands.Push(new VarBool(bool.Parse(s)));
                     continue;
                 }
                 double dNum;
                 int lNum;
                 if (double.TryParse(s, out dNum))
                 {
                     operands.Push(new VarDouble(dNum));
                     continue;
                 }
                 if (int.TryParse(s, out lNum))
                 {
                     operands.Push(new VarInt(lNum));
                     continue;
                 }
                 if (s[0] == '\"')
                 {
                     operands.Push(new VarString(s));
                     continue;
                 }
             }
         }
     }
     return operands.Pop();
 }
Esempio n. 2
0
 protected bool TryParseStandartFunc(string s, ref VarObject res) // Changes
 {
     Regex o = new Regex(@"(.+\(.*\))");
     bool flag = false;
     int i;
     if (o.IsMatch(s))
         return false;
     string subStr = s.Substring(0, s.IndexOf('('));
     for (i = 0; i < Functions.Count; ++i)
     {
         if (subStr == Functions[i].Name)
         {
             flag = true;
             break;
         }
     }
     if (!flag)
         return false;
     res = Functions[i].Do(ParseString(s));
     return true;
 } // Changes
Esempio n. 3
0
 public virtual VarObject Do(VarObject Param)
 {
     return new VarObject();
 }
Esempio n. 4
0
 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);
     }
 }
Esempio n. 5
0
 public override VarObject Do(VarObject Param)
 {
     return new VarDouble(Math.Sin(Param[0].ToDouble()));
 }