When considering the push() and pop() operations for a stack, how could a compiler program use a stack to implement delimiter matching. For example, matching delimiter strings could be: “{â€, “}â€, “(â€, “)â€, and “/*â€, and “*/â€.
Solution
private static final char[] opening = new char[]{\'(\', \'[\', \'{\'};
private static final char[] closing = new char[]{\')\', \']\', \'}\'};
and stack integer can be denoted so that if the value is -1 then there is an error else matched.
How stack is used in delimiter matching:
6) if the stack is not empty finally at the end then report missing right delimiter error
.