Beispiel #1
0
 public static void SameThen(PElm p1, PElm p2, Action <PElm, PElm> action)
 {
     if (p1.Type == p2.Type)
     {
         action(p1, p2);
     }
 }
Beispiel #2
0
 private void DoBinOp(string op)
 {
     PElm.SameThen(_stack[_sp - 1], _stack[_sp], (p1, p2) =>
     {
         var value = op switch
         {
             "add" => p1.Value + p2.Value,
             "sub" => p1.Value - p2.Value,
             "mul" => p1.Value * p2.Value,
             "div" => p1.Value / p2.Value,
             "mod" => p1.Value % p2.Value,
             "and" => p1.Value && p2.Value,
             "or" => p1.Value || p2.Value,
             "equ" => p1.Value == p2.Value,
             "leq" => p1.Value <= p2.Value,
             "les" => p1.Value <p2.Value,
                                "grt" => p1.Value> p2.Value,
             "geq" => p1.Value >= p2.Value,
             "neq" => p1.Value != p2.Value,
             _ => throw new NotSupportedException()
         };
         _stack[--_sp] = new PElm(value);
     });