E=
(d,x,W=[],Q=['_'],h={'(':1,_:8,')':7},z=1,C=n=>{for(;h[q=Q.pop()]<=h[n];W.push(q=='^'?Math.pow(a,b):eval(`a${q}b`)))a=W.pop(b=W.pop());Q.push(q,n)})=>([...d].map(l=>h[l='+-/*^'['ASDME'.search(l)]]=(d+=!!l),d=1),(x+')').replace(/\D|\d+/g,t=>(u=~~h[t])-1?u-7?u?z&&t=='-'?z=-z:C(t,z=1):(W.push(z*t),z=0):Q.pop(Q.pop(C(t),z=0)):(z=!!Q.push('_'),z=1)),W.pop())
// TEST
console.log=(...x)=>O.innerHTML+=x.join` `+'\n'
console.log(E('MDASE','3+4*5^2'))
console.log(E("EMDAS", "3+6*2/4-1")) // 5
console.log(E("DAMES", "3+6*2/4-1")) //3.5
console.log(E("SAD, ME", "3+6*2/4-1")) // 6
console.log(E("ME ADS", "3+5^4/2-3*2")) // 308
console.log(E("AM EDS", "4*3-sin(0.5^2)*3+1")) // 11.01038 sin not supported
console.log(E("DAMES", "4-5-6")) // -7
// MORE READABLE
U=(d,x,W=[],Q=['_'],h={'(':1,_:8,')':7},z=1,
C=n=>{
for(;h[q=Q.pop()]<=h[n];
W.push(q=='^'?Math.pow(a,b):eval(`a${q}b`)))
a=W.pop(b=W.pop());
Q.push(q,n)
}
)=>(
[...d].map(l=>h[l='+-/*^'['ASDME'.search(l)]]=(d+=!!l),d=1),
(x+')').replace(/\D|\d+/g,t=>
(u=~~h[t])-1
?u-7
?u
?z&&t=='-'?z=-z:C(t,z=1)
:(W.push(z*t),z=0)
:Q.pop(Q.pop(C(t),z=0))
:(Q.push('_'),z=1)
),
W.pop()
)
<pre id=O></pre>