#JavaScript (ES6), 10098 bytes
Inspired by notjagan's Python answer. Turns the input expression into a huge and ugly executable string.
s=>eval(s.split`)(`.join`)*(`.split`(`.join`(g=(n,k)=>(C=d=>n%--d?C(d):d>1k-=d<2)(++n)||--k?g(n,k):n)(1,`)
Merging the C
and g
functions into a single one may save some bytes, but it would require even more recursion.
###Test cases
let f =
s=>eval(s.split`)(`.join`)*(`.split`(`.join`(g=(n,k)=>(C=d=>n%--d?C(d):d>1k-=d<2)(++n)||--k?g(n,k):n)(1,`)
console.log(f("()()((()))((()))")) // => 100
console.log(f("(()(()(())))")) // => 101
console.log(f("(()())(((())))(()(()))")) // => 1001
console.log(f("(((((((())))))))")) // => 5381
console.log(f("(()())((((()))))(()()(())(()))")) // => 32767
console.log(f("()()()()()()()()()()()()()()()")) // => 32768