Esempio n. 1
0
        /// FACTORIAL_FACTOR: PRIMARY '!'?                             Factor
        /// 5!
        private ASTNode ParseFactorialFactor( )
        {
            var node = ParsePrimary();

            if (IsNext(Token.TokenType.Factorial))
            {
                node = new FactorialUnaryOperatorASTNode(Accept( ), node);
            }
            return(node);
        }
Esempio n. 2
0
        protected 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("Factorial only supports Positive Integers");
            }
            return(fact(value));
        }
Esempio n. 3
0
        /// FACTORIAL_FACTOR: PRIMARY '!'?
        private bool TryParseFactorialFactor(out ASTNode node)
        {
            if (TryParsePrimary(out node))
            {
                if (IsNext(Token.TokenType.Factorial))
                {
                    node = new FactorialUnaryOperatorASTNode(Accept( ), node);
                }
            }

            return(node != null);
        }