Beispiel #1
0
 static void ConsumeTillOpenParen(SmashTheState state, bool discardParen)
 {
     while (state.OpPeekType() != TokenType.ParenOpen)
     {
         DoCalculation(state);
     }
     if (discardParen)
     {
         state.PopOpStack();
     }
 }
Beispiel #2
0
        static void DoFunction(SmashTheState state)
        {
            var token = (CalcFuncToken)state.PopOpStack();
            var func  = token.Func;

            double[] args = new double[func.ArgCount];
            // Reverse, since the first out was the last argument in.
            for (int i = func.ArgCount - 1; i >= 0; i--)
            {
                args[i] = state.PopOutput();
            }
            state.Push(func.Apply(args));
        }
Beispiel #3
0
        static void DoCalculation(SmashTheState state)
        {
            var token = state.PopOpStack();

            switch (token.Type)
            {
            case TokenType.Operator:
                var opToken = (CalcOpToken)token;
                DoCalculation(state, opToken.OpType);
                break;

            case TokenType.Function:
                throw new InvalidOperationException("WAKE ME UP");

            default:
                throw new InvalidOperationException("CAN'T WAKE UP");
            }
        }