It has the following steps,
- If the character is an opening symbol push it onto the stack.
- If the character is a closing symbol and if the stack is empty report an error as missing opening symbol.
- If it is a closing symbol and if it has corresponding opening symbol in the stack pop it from the stack otherwise report an error as mismatched symbols.
- At the end of file,if the stack is not empty,report an error as missing closing symbols.
EXAMPLE 1:
Consider the expression as "(a+b)#"
Fig:Illustration for Balanced symbol
EXAMPLE 2:
Consider the expression "((a+b)#"
No comments:
Post a Comment