Microsoft.R.Core.AST.Operators.Operator.IsPossibleUnary C# (CSharp) Method

IsPossibleUnary() private static method

private static IsPossibleUnary ( OperatorType operatorType ) : bool
operatorType OperatorType
return bool
        private static bool IsPossibleUnary(OperatorType operatorType) {
            switch (operatorType) {
                case OperatorType.Subtract:
                case OperatorType.Add:
                case OperatorType.Tilde:
                case OperatorType.Not:
                case OperatorType.Help:
                    return true;
            }
            return false;
        }

Usage Example

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);
        }