Implemented stack-based algorithm for matching emphasis