Submit the source code files on Ecampus under the "Submit Homework" menu option.

Using the flat assembler (fasm), write a program that reads in a string of various parentheses, brackets, and braces.  Output whether or not the parentheses, brackets, and braces are balanced.  You must use the algorithm I show in my tutorial video.


The algorithm below can be used to check if parenthesis, brackets, and braces are balanced in an equation.
Balanced input strings:  
(a) (([{}]))     (b) (()[]{[]})     (c) {([]([{({{}})([()])[][]}])[](()){()})}
Unbalanced input strings:  
(a) )(     (b) [(])     (c) (([]{})

Loop - Step through each character (token) of the input string
{
     if token is an opening (, [, or {, then push it to the stack.

     else if token is a closing ), ], or }, AND the stack is empty, then it's not balanced (false)

     else if token is a ), then pop from the stack.  If it isn't a (, then
it's not balanced (false)

     else if token is a ], then pop from the stack.  If it isn't a [, then
it's not balanced (false)

     else if token is a }, then pop from the stack.  If it isn't a {, then
it's not balanced (false)
}
if the stack is empty, equation is balanced (true)
else equation is not balanced (false)


Example output
This program checks if the parentheses, brackets, and braces are balanced.
Please enter a string:
(()[]{[]})
This string is balanced.


This program checks if the parentheses, brackets, and braces are balanced.
Please enter a string:
{[])[()]}
This string is not balanced.