Ejemplo n.º 1
0
        private double Evaluate(FactorialUnaryOperatorAstNode node)
        {
            int Fact(int x) => x == 1 ? 1 : x *Fact(x - 1);

            var value = (int)Evaluate(node.Target as dynamic);

            if (value < 0)
            {
                throw new Exception("Only positive integers allowed.");
            }
            return(Fact(value));
        }
Ejemplo n.º 2
0
        private bool TryParseFactorialFactor(out AstNode node)
        {
            if (TryParsePrimary(out node))
            {
                if (IsNext(TokenType.Factorial))
                {
                    node = new FactorialUnaryOperatorAstNode(Accept(), node);
                }
            }

            return(node != null);
        }