Microsoft.R.Core.AST.Operators.OperatorAssociativity.GetAssociativity C# (CSharp) Method

GetAssociativity() public static method

public static GetAssociativity ( OperatorType operatorType ) : Associativity
operatorType OperatorType
return Associativity
        public static Associativity GetAssociativity(OperatorType operatorType) {
            switch (operatorType) {
                case OperatorType.Exponent:
                case OperatorType.LeftAssign:
                case OperatorType.Equals:
                    return Associativity.Right;
            }
            return Associativity.Left;
        }
    }

Usage Example

Ejemplo n.º 1
0
        public override bool Parse(ParseContext context, IAstNode parent)
        {
            Debug.Assert(context.Tokens.CurrentToken.TokenType == RTokenType.Operator);

            OperatorType  = TokenOperator.GetOperatorType(context.TextProvider.GetText(context.Tokens.CurrentToken));
            OperatorToken = RParser.ParseToken(context, this);
            Associativity = OperatorAssociativity.GetAssociativity(OperatorType);

            // If operator is preceded by an operator, it is then unary
            // Look back two tokens since operator parsing already consumed its token.
            if (IsUnary || IsUnaryOperator(context.Tokens, context.TextProvider, OperatorType, -2))
            {
                OperatorType  = Operator.GetUnaryForm(OperatorType);
                IsUnary       = true;
                Associativity = Associativity.Right;
            }
            return(base.Parse(context, parent));
        }
OperatorAssociativity