Monday, March 4, 2019

BALANCING THE SYMBOL PROBLEM

It has the following steps,
  1. If the character is an opening symbol push it onto the stack.
  2. If the character is a closing symbol and if the stack is empty report an error as missing opening symbol.
  3. 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.
  4. 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)#"
                                               
    
  Fig:Illustration for unbalanced symbol
                                  

No comments:

Post a Comment