var arr=[
'(((1+2)+3)*10-(3-1)))/10=',
'(((1+2)+3)*10-(3-1))/10=',
'(((1+)2)+3)*10-(3-1))/10=',
'(((1+2()+3)*10-(3-1))/10='
]
function rep (a){
var c=a;
var b=true;
while (a.search(/[\(\)]/g)!= -1&&b) {
a = a.replace(/\([^\(\)]+\)/g,'$');//alert(a)
b = a.split(/\(|\)/).length!=2 && a.replace(/\(\)/g,'')==a;
}
if(b){b=eval(c.replace("=",""))}
return b;
}
for(var i in arr){
alert('N='+i+'\n'+arr[i]+' ' +rep (arr[i]+';'));
}