private Argument ExecuteOperator(Operator op, Stack<Argument> stack)
        {
            if (stack.Count < 2)
            {
                throw new InvalidOperationException("Too few arguments for operator");
            }

            var arg2 = stack.Pop();
            var arg1 = stack.Pop();

            return op.CalculateResult(arg1, arg2);
        }
Exemple #2
0
 void RelOp(out Operator op)
 {
     op = Operator.Bad;
     switch (la.kind) {
     case 11: {
     Get();
     op = Operator.Eq;
     break;
     }
     case 12: {
     Get();
     op = Operator.Ne;
     break;
     }
     case 13: {
     Get();
     op = Operator.Lt;
     break;
     }
     case 14: {
     Get();
     op = Operator.Le;
     break;
     }
     case 15: {
     Get();
     op = Operator.Gt;
     break;
     }
     case 16: {
     Get();
     op = Operator.Ge;
     break;
     }
     default: SynErr(23); break;
     }
 }
Exemple #3
0
 void OrOp(out Operator op)
 {
     op = Operator.Bad;
     Expect(10);
     op = Operator.Or;
 }
Exemple #4
0
 void MulOp(out Operator op)
 {
     op = Operator.Bad;
     if (la.kind == 19) {
     Get();
     op = Operator.Mul;
     } else if (la.kind == 20) {
     Get();
     op = Operator.Div;
     } else SynErr(26);
 }
Exemple #5
0
 void AndOp(out Operator op)
 {
     op = Operator.Bad;
     Expect(9);
     op = Operator.And;
 }
Exemple #6
0
 void AddOp(out Operator op)
 {
     op = Operator.Bad;
     if (la.kind == 17) {
     Get();
     op = Operator.Add;
     } else if (la.kind == 18) {
     Get();
     op = Operator.Sub;
     } else SynErr(24);
 }
 public UnaryOperation(Operator op, Expression expression)
 {
     _op = op;
     _expression = expression;
 }
 public BinaryOperation(Operator op, Expression e1, Expression e2)
 {
     _op = op;
     _e1 = e1;
     _e2 = e2;
 }