IsPossibleUnary() private static method

private static IsPossibleUnary ( OperatorType operatorType ) : bool
operatorType OperatorType
return bool
Ejemplo n.º 1
0
        /// <summary>
        /// Given token stream and operator type determines if operator is unary
        /// </summary>
        /// <param name="tokens">Token stream</param>
        /// <param name="operatorType">Operator type</param>
        /// <param name="offset">Offset of the operator relatively to the current token position</param>
        public static bool IsUnaryOperator(TokenStream <RToken> tokens, OperatorType operatorType, int offset = 0)
        {
            bool possibleUnary = Operator.IsPossibleUnary(operatorType);

            if (!possibleUnary)
            {
                return(false);
            }

            if (tokens.Position == offset)
            {
                // First operator in the expression is unary
                return(true);
            }

            // If operator is preceded by an operator, it is then unary
            // Look back two tokens since operator parsing already consumed its token.
            if (tokens.LookAhead(offset - 1).TokenType == RTokenType.Operator)
            {
                return(true);
            }

            return(false);
        }