previous | start | next

Balanced Delimiters

Problem:

Write a class BalancedApp with a static main method that will parse an input file to check that it has properly balanced curly braces, square brackets, and parentheses - '{', '}', '[', ']', '(', and ')'.

If 'x' stands for any character other than the delimiters, here are grammar rules for forming a properly balanced text:

 S -> '(' S ') | '[' S ']' | '{' S '}'| S S | 'x'      
   

For example, the input

 [ ( { x x } x ) ] ( x )
   

can be generated by these rules, but

 ( x [ x ) ] 
   

cannot!



previous | start | next