public void AddTokenMatcher(ITokenMatcher tokenMatcher, TokenType tokenType, int precedence, OperatorAssociativity associativity, TokenEvaluator tokenEvaluator, int?numTerms = null)
        {
            var matcher = new ExpressionTokenMatcher(tokenMatcher, tokenType, precedence, associativity, tokenEvaluator);

            if (numTerms != null)
            {
                matcher.NumTerms = numTerms;
            }

            AddTokenMatcher(matcher);
        }
        public void AddTernaryTokenMatcher(ITokenMatcher matcher1, ITokenMatcher matcher2, int precedence, OperatorAssociativity associativity, TokenEvaluator tokenEvaluator)
        {
            ExpressionTokenMatcher root = new ExpressionTokenMatcher(null, TokenType.TernaryOperator, tokenEvaluator);

            ExpressionTokenMatcher partial1 = new ExpressionTokenMatcher(matcher1, TokenType.TernaryOperator1, precedence, associativity, null);
            ExpressionTokenMatcher partial2 = new ExpressionTokenMatcher(matcher2, TokenType.TernaryOperator1, precedence, associativity, null);

            partial1.Root = root;
            partial2.Root = root;

            AddTokenMatcher(partial1);
            AddTokenMatcher(partial2);
        }
Exemple #3
0
        public ExpressionToken(ExpressionTokenMatcher tokenMatcher, string text)
            : base(tokenMatcher, text)
        {
            switch (tokenMatcher.TokenType)
            {
                case TokenType.TernaryOperator: _numTerms = 3; break;
                case TokenType.UnaryOperator: _numTerms = 1; break;
                case TokenType.Operator: _numTerms = 2; break;
            }

            _precedence = tokenMatcher.Precedence;
            _associativity = tokenMatcher.Associativity;
            _tokenType = tokenMatcher.TokenType;
            _evaluator = tokenMatcher.Evaluator;
        }
Exemple #4
0
        public ExpressionToken(ExpressionTokenMatcher tokenMatcher, string text) : base(tokenMatcher, text)
        {
            switch (tokenMatcher.TokenType)
            {
            case TokenType.TernaryOperator: _numTerms = 3; break;

            case TokenType.UnaryOperator: _numTerms = 1; break;

            case TokenType.Operator: _numTerms = 2; break;
            }

            if (tokenMatcher.NumTerms != null)
            {
                _numTerms = tokenMatcher.NumTerms.Value;
            }

            _precedence    = tokenMatcher.Precedence;
            _associativity = tokenMatcher.Associativity;
            _tokenType     = tokenMatcher.TokenType;
            _evaluator     = tokenMatcher.Evaluator;
        }