#include "BracketChecker.h"
#include"Stack.h"


bool BracketChecker::isBalance(string exp)
{
i=0;
Stack stack;
while(exp[i]) 
  {
    if (isSymbol(exp[i]))
    {
        if(isOpener(exp[i]))
           stack.push(exp[i]);
                      
        else
        {
          if(exp[i]!=matchingChar(stack.pop()))
             return false;
        }   
    }
    i++;
  }   

if(stack.isEmpty())
   return true;
else
   return false;
}

bool BracketChecker::isOpener(char exp)
{
 if (exp=='[' || exp=='{' || exp=='(')
     return true;
 else
     return false;
}

bool BracketChecker::isCloser(char exp)
{
 if (exp==']' || exp=='}' || exp==')')
     return true;
 else
     return false;
}

bool BracketChecker::isSymbol(char exp)
{
 if(exp=='(' || exp==')' || exp=='{' || exp=='}' || exp=='[' || exp==']')
    return true;
 else
    return false;
}

char BracketChecker::matchingChar(char exp)
{
 if(exp=='(')
    return ')'; 
 if(exp=='{')
    return '}';
 if(exp=='[')
    return ']';
}
