BAE Systems interview question

Write an algorithm to ensure parentheses are matched in a string.