Esempio n. 1
0
 public int ModuloConstants(string input, Constant constant)
 {
     Parser parse = new Parser();
     int constant_value;
     int number_value;
     Char result1;
     Char result2;
     int result3;
     int result4;
     bool test1 = Char.TryParse(parse.GetFirst(input), out result1);
     bool test2 = Char.TryParse(parse.GetSecond(input), out result2);
     bool test3 = int.TryParse(parse.GetFirst(input), out result3);
     bool test4 = int.TryParse(parse.GetSecond(input), out result4);
     if (test1 && !test3 && test4)
     {
         constant_value = constant.GetConstant(result1);
         number_value = result4;
     }
     else if (test2 && !test4 && test3)
     {
         constant_value = constant.GetConstant(result2);
         number_value = result3;
     }
     else if (test1 && test2 && !test3 && !test4)
     {
         constant_value = constant.GetConstant(result1);
         number_value = constant.GetConstant(result2);
     }
     else
     {
         throw new FormatException();
     }
     return constant_value % number_value;
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int count = 0;
            Parser parse = new Parser();
            Constant constant = new Constant();
            Evaluate evaluate_input = new Evaluate();
            Char result1;
            Char result2;
            int result3;
            int result4;

            while (true)
            {
                Console.Write("[{0}]", count);
                string input = Console.ReadLine();
                if (input.ToLower() == "exit" || input.ToLower() == "quit")
                {
                    break;
                }
                bool testIfFirstIsChar = Char.TryParse(parse.GetFirst(input), out result1);
                bool testIfSecondIsChar = Char.TryParse(parse.GetSecond(input), out result2);
                bool testIfFirstIsNum = int.TryParse(parse.GetFirst(input), out result3);
                bool testIfSecondIsNum = int.TryParse(parse.GetSecond(input), out result4);
                if (input.Length == 1)
                {
                    Console.WriteLine(" = {0} is {1}", input, constant.GetConstant(char.Parse(input)));
                }
                else if (testIfFirstIsChar && !testIfFirstIsNum && parse.GetOperator(input) == '=')
                {
                    constant.AddConstant(result1, result4);
                    Console.WriteLine("= '{0}' is '{1}' ", result1, result4);
                }
                else if (testIfFirstIsChar && !testIfFirstIsNum && testIfSecondIsNum || testIfSecondIsChar && !testIfSecondIsNum && testIfFirstIsNum || !testIfFirstIsNum && !testIfSecondIsNum)
                {
                    Console.WriteLine("= {0}", evaluate_input.EvaluateInput(input, constant));
                }
                else if (testIfFirstIsNum && testIfSecondIsNum)
                {
                    Console.WriteLine("= {0}", evaluate_input.EvaluateInput(input));
                }
                count++;
            }
        }
Esempio n. 3
0
 public void ConstantEnsureICanRetrieveFromDictionary()
 {
     Constant constant = new Constant();
     constant.AddConstant('x', 5);
     Assert.AreEqual(5, constant.GetConstant('x'));
 }