stack example delimiter matching one common use for stacks is to parse certain kinds of text strings typicallythe strings are lines of code in computer languageand the programs parsing them are compilers to give the flavor of what' involvedwe'll show program that checks the delimiters in line of text typed by the user this text doesn' need to be line of real java code (although it could be)but it should use delimiters the same way java does the delimiters are the braces and }brackets and ]and parentheses and each opening or left delimiter should be matched by closing or right delimiterthat isevery should be followed by matching and so on alsoopening delimiters that occur later in the string should be closed before those occurring earlier here are some examplesc[da{ [ ] } { ( ] } [ { } ]ea{ ( /correct /correct /not correctdoesn' match /not correctnothing matches final /not correctnothing matches opening opening delimiters on the stack this delimiter-matching program works by reading characters from the string one at time and placing opening delimiters when it finds themon stack when it reads closing delimiter from the inputit pops the opening delimiter from the top of the stack and attempts to match it with the closing delimiter if they're not the same type (there' an opening brace but closing parenthesisfor example)an error occurs alsoif there is no opening delimiter on the stack to match closing oneor if delimiter has not been matchedan error occurs delimiter that hasn' been matched is discovered because it remains on the stack after all the characters in the string have been read let' see what happens on the stack for typical correct stringa{ ( [ ] )ftable shows how the stack looks as each character is read from this string the entries in the second column show the stack contentsreading from the bottom of the stack on the left to the top on the right as the string is readeach opening delimiter is placed on the stack each closing delimiter read from the input is matched with the opening delimiter popped from the top of the stack if they form pairall is well non-delimiter characters are not inserted on the stackthey're ignored