Beispiel #1
0
 private static string TranslateCondition(string[] words, int index, string prev)
 {
   string s1 = words[index++];
   string str1 = "";
   while ((int) s1[0] == 33)
   {
     s1 = words[index - 1] = s1.Substring(1);
     str1 += "@5";
   }
   if (s1 == "-")
     s1 = words[index - 1] = s1 + words[index];
   string str2 = (int) s1[0] != 40 || (int) s1[s1.Length - 1] != 41 ? str1 + ConditionTranslator.GetFunc(s1) : str1 + ConditionTranslator.TranslateCondition(ConditionTranslator.GetWords(s1.Substring(1, s1.Length - 2)), 0, (string) null);
   if (str2 == null)
     return (string) null;
   if (index >= words.Length - 1)
     return prev == null ? str2 : prev + str2;
   string s2 = ConditionTranslator.GetSign(words[index++]);
   if (s2 == null)
   {
     ConditionTranslator.LastMessage = "Expected an operator.";
     return (string) null;
   }
   int num1 = ConditionTranslator.CondType(s2);
   if (num1 == 5)
     s2 = "@5" + ConditionTranslator.GetSign("==");
   if (prev == null)
     return ConditionTranslator.TranslateCondition(words, index, s2 + str2);
   int num2 = ConditionTranslator.CondType(prev);
   switch (num1)
   {
     case 5:
     case 13:
     case 14:
     case 15:
       if (num2 == 6 || num2 == 7)
         return ConditionTranslator.TranslateCondition(words, index, prev + s2 + str2);
       if (num2 > 7 && num2 < 13)
         return ConditionTranslator.TranslateCondition(words, index, s2 + prev + str2);
       return (string) null;
     case 6:
     case 7:
       if (num2 > 4 && num2 < 8 || num2 > 12 && num2 < 16)
         return ConditionTranslator.TranslateCondition(words, index, s2 + prev + str2);
       return (string) null;
     case 9:
     case 10:
       if (num2 == 5 || num2 == 9 || num2 == 10 || num2 > 12 && num2 < 16)
         return ConditionTranslator.TranslateCondition(words, index, prev + s2 + str2);
       if (num2 == 11 || num2 == 12)
         return ConditionTranslator.TranslateCondition(words, index, s2 + prev + str2);
       return (string) null;
     case 11:
     case 12:
       if (num2 == 5 || num2 > 8 && num2 < 16)
         return ConditionTranslator.TranslateCondition(words, index, prev + s2 + str2);
       return (string) null;
     default:
       return (string) null;
   }
 }
Beispiel #2
0
 public static string TranslateCondition(string text)
 {
   if (Enumerable.Contains(text, '@'))
   {
     ConditionTranslator.LastMessage = "Input contains invalid characters.";
     return null;
   }
   text = ConditionTranslator.FixMissingSpaces(text).Trim();
   if (Enumerable.Count(text, x => (int)x == 40) != Enumerable.Count(text, x => (int)x == 41))
   {
     ConditionTranslator.LastMessage = "Uneven amount of open and closed brackets.";
     return null;
   }
   if (text.Length == 0)
     return "@[email protected]";
   text = ConditionTranslator.ReplaceFunctions(text);
   if (text == null)
     return null;
   return ConditionTranslator.TranslateCondition(ConditionTranslator.GetWords(text), 0, (string) null);
 }