Add extra semantic code, so that the code will print
each parenthesis along with the level of nesting
of that parenthesis.
The level should be printed after a left paren
and followed by a blank. A right paren should be
preceded by a blank, then the level number,
and then the right paren. (Notice that your semantic
code must also print the parens.) Here are several examples
of runs with the correct output.
(In each case the input is in boldface.)
You must not write this code from scatch, but you must
add to the parser above.
(()())#
(0 (1 1)(1 1) 0)
( () (( )) (() () ) () ) #
(0 (1 1)(1 (2 2) 1)(1 (2 2)(2 2) 1)(1 1) 0)
((((((((((()))))))))))#
(0 (1 (2 (3 (4 (5 (6 (7 (8 (9 (10 10) 9) 8) 7) 6) 5) 4) 3) 2) 1) 0)
( () (( )) (()) () (((() (()) ) () ) ) )#
(0 (1 1)(1 (2 2) 1)(1 (2 2) 1)(1 1)(1 (2 (3 (4 4)(4 (5 5) 4) 3)(3 3) 2) 1) 0)