Exemplo n.º 1
0
 /// <summary>
 /// Перевірка виразу посимвольно через стек відкритих дужок
 /// </summary>
 /// <param name="letter">Символ</param>
 /// <returns></returns>
 private bool Check(char letter)
 {
     //Якщо це дужка ( чи [, то поміщуємо у стек
     if (BracketExpression.IsOpenedBracket(letter))
     {
         _bracketExpressions.Push(ExpressionChecker.CreateExpression(letter));
         return(true);
     }
     //Якщо дужка ) чи ], то видаляємо з стеку, також закриваємо вираз
     if (BracketExpression.IsClosedBracket(letter))
     {
         var previous = _bracketExpressions.Peek();
         var res      = previous.Close(letter);
         if (res)
         {
             _bracketExpressions.Pop();
         }
         return(res);
     }
     return(true);
 }
Exemplo n.º 2
0
        static void TestBalancedExpressionChecker()
        {
            var checker  = new ExpressionChecker();
            var input    = "(1 + 2)";
            var balanced = checker.IsBalanced(input);

            Console.WriteLine($"Expression: '{input}' , Is Balanced: {balanced}");

            // 2nd case
            input    = "(1 + 2";
            balanced = checker.IsBalanced(input);
            Console.WriteLine($"Expression: '{input}' , Is Balanced: {balanced}");

            // 3rd case
            input    = "((1 + 2)";
            balanced = checker.IsBalanced(input);
            Console.WriteLine($"Expression: '{input}' , Is Balanced: {balanced}");

            // 4th case
            input    = "(1 + 2>";
            balanced = checker.IsBalanced(input);
            Console.WriteLine($"Expression: '{input}' , Is Balanced: {balanced}");

            // 5th case
            input    = ")1 + 2(";
            balanced = checker.IsBalanced(input);
            Console.WriteLine($"Expression: '{input}' , Is Balanced: {balanced}");

            // 6th case
            input    = "";
            balanced = checker.IsBalanced(input);
            Console.WriteLine($"Expression: '{input}' , Is Balanced: {balanced}");

            // 7th case
            input    = "[1 , 6]";
            balanced = checker.IsBalanced(input);
            Console.WriteLine($"Expression: '{input}' , Is Balanced: {balanced}");
        }
Exemplo n.º 3
0
        public SqlExpression CheckExpression(SqlExpression expression)
        {
            var expChecker = new ExpressionChecker(this);

            return(expChecker.Visit(expression));
        }
Exemplo n.º 4
0
 public SqlExpression CheckExpression(SqlExpression expression)
 {
     var expChecker = new ExpressionChecker(this);
     return expChecker.Visit(expression);
 }