Dames, do some math! The order of operations, PEMDAS, is a basic rule in mathematics telling us which order operations should be performed:

"Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction"

The problem is, PEMDAS is not very versatile! What if you wanted to do it in another order? We won't mess with the parentheses, so we keep them where they are (first).

Create a program that takes two arguments:


A string, telling which order the operations should follow. Some examples are "DAMES", "SAD, ME", "ME SAD", "MEADS". Yes, spaces and commas are OK, as it makes the order easier to remember. 


Following suggestions in chat: Supporting spaces and commas is now optional.
If one of the letters is missing, or if there are additional letters that shouldn't be there, you can consider the input invalid and treat it however you like.

A string, or an expression containing the expression that should be evaluated.


Return the result of the expression as either a decimal number, or an integer. If the answer is not an integer, it has to be returned as a decimal number.

Rules:


It's OK to combine the two input arguments into one, if that's easier in your language.
It doesn't have to be a string, but it has to have letters. You can't substitute Addition with 1, Division with 2, etc.
You can choose which input is first.
The expression is evaluated right to left left to right. (Change of rule. Any submissions poster the first 12 hours that have this the other way around are accepted).
The operations use the symbols: ( ) ^ * / + -. For instance, you can't use ¤ instead of + for addition. 
Spaces in the input expression is not valid as input
Unary +/- is not valid as input if it directly follows + or -. Consider 3+-2 as invalid input. It can be treated however you like (doesn't have to produce an error). If + or - follows any other operator than plus or minus, it's treated the usual way: 3*-3 = -9, sin(-2)=-0.909
The program must strictly follow the letters, so "EMDAS", 1-3+4 =&gt; -6, and "EMDSA", 1-3+4 =&gt; 2.


Examples:

Input:   "EMDAS", "3+6*2/4-1"   // -&gt; 3+12/4-1 -&gt; 3+3-1 -&gt; 6-1 -&gt; 5
Output:  5

Input:   "DAMES", "3+6*2/4-1"   // -&gt; 3+6*0.5-1 -&gt; 9*0.5-1 -&gt; 4.5-1 -&gt; 3.5
Output:  3.5

Input:   "SAD, ME", "3+6*2/4-1"  // -&gt; 3+6*2/3 -&gt; 9*2/3 -&gt; 9*0.66667 -&gt; 6   
Output:  6

Input:   "ME ADS", "3+5^4/2-3*2 // -&gt; 3+5^4/2-6 -&gt; 3+625/2-6 -&gt; 628/2-6 -&gt; 314-6 -&gt; 308
Output:  308

Input:   "AM EDS", "4*3-sin(0.5^2)*3+1" // -&gt; 4*3-sin(0.5^2)*4 -&gt; 12-sin(0.5^2)*4 -&gt; 4*3-(4*sin(0.5^2)) -&gt; 12-(4*sin(0.5^2)) -&gt; 12-(4*sin(0.25)) -&gt; 12-(4*0.24740) -&gt; 12-0.98961 -&gt; 11.01038
Output:  11.01038

Input:   "DAMES", "4-5-6"   // -&gt; (4-5)-6 -&gt; = -7  
Output:  -7                  // NOT: -&gt; 4-(5-6) -&gt; 4-(-1) -&gt; 5


Note, the parentheses where added to show that the multiplication 4*sin(0.5^2) is evaluated before the exponentiation. 

This is code golf, so the shortest code in bytes win.
JavaScript (ES6) 349 353 387 400
... maybe still golfable
This old parser of mine sometimes comes in handy - (already used in other 2 challenges)


E=
(d,x,W=[],Q=['_'],h={'(':1,_:8,')':7},z=1,C=n=&gt;{for(;h[q=Q.pop()]&lt;=h[n];W.push(q=='^'?Math.pow(a,b):eval(`a${q}b`)))a=W.pop(b=W.pop());Q.push(q,n)})=&gt;([...d].map(l=&gt;h[l='+-/*^'['ASDME'.search(l)]]=(d+=!!l),d=1),(x+')').replace(/\D|\d+/g,t=&gt;(u=~~h[t])-1?u-7?u?z&amp;&amp;t=='-'?z=-z:C(t,z=1):(W.push(z*t),z=0):Q.pop(Q.pop(C(t),z=0)):z=!!Q.push('_')),W.pop())

// TEST
console.log=(...x)=&gt;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=&gt;{
    for(;h[q=Q.pop()]&lt;=h[n];
        W.push(q=='^'?Math.pow(a,b):eval(`a${q}b`)))
      a=W.pop(b=W.pop());
    Q.push(q,n)
  }
)=&gt;(
  [...d].map(l=&gt;h[l='+-/*^'['ASDME'.search(l)]]=(d+=!!l),d=1),
  (x+')').replace(/\D|\d+/g,t=&gt; 
     (u=~~h[t])-1
       ?u-7
         ?u
           ?z&amp;&amp;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()
)
&lt;pre id=O&gt;&lt;/pre&gt;



Ungolfed


Evaluate=(oprec,expr)=&gt;
{
  var tokens = expr.match(/\D|\d+/g).concat(')')
  var t,a,b,v, SignV
  var vstack=[]
  var ostack=['_']
  var op={ '(':8, _: 1, ')':2}
  oprec.match(/\w/g).map((l,p)=&gt;op['+-/*^'['ASDME'.search(l)]]=7-p)
  var OPush=o=&gt;ostack.push(o)
  var OPop=_=&gt;ostack.pop()
  var VPush=v=&gt;vstack.push(v)
  var VPop=v=&gt;vstack.pop()

  var Scan=i=&gt;
  {
    SignV = 1
    for (; t=tokens[i++]; )
    {
      if (t == '(')  
      {
        OPush('_')
        SignV = 1
      }
      else if (t == ')')
      {
        CalcOp(t);
        OPop();
        OPop();
        SignV = 0
      }
      else if (op[t])
      {
        if (SignV &amp;&amp; t=='-')
          SignV = -SignV
        else
          CalcOp(t), SignV = 1
      }  
      else
      {
        VPush(SignV*t)
        SignV=0
      }
    }
  }
  var CalcOp=nop=&gt;
  {
    for (; op[po = OPop()] &gt;= op[nop];)
      b=VPop(), a=VPop(), CalcV(a,b,po);
    OPush(po), OPush(nop);
  }
  var CalcV=(a,b,o)=&gt;
  {
//    console.log('CV',a,b,o)
    if (o=='+')
      a+=b
    if (o=='-')
      a-=b
    if (o=='*')
      a*=b
    if (o=='/')
      a/=b
    if (o=='^')
      a=Math.pow(a,b)
    VPush(a)
  }
  Scan(0)

  return VPop()
}

console.log=(...x)=&gt;O.innerHTML+=x.join` `+'\n'

console.log(Evaluate('MDASE','3+4*5^2'))
console.log(Evaluate('EMDAS','3+6*2/4-1')) // 5
console.log(Evaluate("DAMES", "3+6*2/4-1")) //3.5
console.log(Evaluate("SAD, ME", "3+6*2/4-1")) // 6
console.log(Evaluate("ME ADS", "3+5^4/2-3*2")) // 308
console.log(Evaluate("AM EDS", "4*3-sin(0.5^2)*3+1")) // 11.01038 sin not supported
console.log(Evaluate("DAMES", "4-5-6")) // -7
&lt;pre id=O&gt;&lt;/pre&gt;