Evaluating Parentheses and Brackets as Integers Write a program that takes in a string of the four characters ()[] that satisfies these points:


Every left parenthesis ( has a matching right parenthesis ).
Every left bracket [ has a matching right bracket ].
Matching pairs of parentheses and brackets won't overlap. e.g. [(]) is invalid because the matching brackets are not fully contained in the matching parentheses, nor vice-versa.
The first and last characters are a matching pair of parentheses or brackets. So ([]([])) and [[]([])] are valid but []([]) is not.


(A grammar for the input format is &lt;input&gt; ::= [&lt;input&gt;*] | (&lt;input&gt;*).)

Each pair of matching parentheses and brackets evaluates to a non-negative integer:


The values of pairs inside matching parentheses are all summed. The empty  match () has value 0.
The values of pairs inside matching brackets are all multiplied. The empty match [] has value 1.


(The sum or product of one number is that same number.)

For example, ([](())([][])[()][([[][]][][])([][])]) can be broken down and evaluated as 9:

([](())([][])[()][([[][]][][])([][])])    &lt;input&gt;
(1 (0 )(1 1 )[0 ][([1 1 ]1 1 )(1 1 )])    &lt;handle empty matches&gt;
(1 0   2     0   [(1     1 1 )2     ])    &lt;next level of matches&gt;
(1 0   2     0   [3           2     ])    &lt;and the next&gt;
(1 0   2     0   6                   )    &lt;and the next&gt;
9                                         &lt;final value to output&gt;


Another example:

[([][][][][])([][][])([][][])(((((([][]))))))]    &lt;input&gt;
[(1 1 1 1 1 )(1 1 1 )(1 1 1 )((((((1 1 ))))))]
[5           3       3       (((((2     )))))]
[5           3       3       ((((2       ))))]
[5           3       3       (((2         )))]
[5           3       3       ((2           ))]
[5           3       3       (2             )]
[5           3       3       2               ]
90                                                &lt;output&gt;


Your program needs to evaluate and print the integer represented by the entire input string. You can assume the input is valid. The shortest code in bytes wins.

Instead of a program, you may write a function that takes in a string and prints or returns the integer.
CJam, 23

q"])(""1]:*0]:+["4/ers~


With BIG credits to Dennis! Try it online

Explanation:

The program converts the input to a CJam expression then evaluates it.
[…] becomes […1]:* (append 1 and multiply)
(…) becomes […0]:+ (append 0 and add)

q              read input
"])("          characters we want to replace
"1]:*0]:+["    replacement strings, concatenated
4/             split into strings of length 4: ["1]:*" "0]:+" "["]
er             replace (transliterate) the 3 characters with the 3 strings
s              convert the result (mixed characters and strings) to string
~              evaluate