Esempio n. 1
0
        public void AddTernaryOperator(string pattern1, string pattern2, int precedence, OperatorAssociativity associativity, TokenEvaluator evaluator)
        {
            TokenDefinition root = new TokenDefinition(TokenType.TernaryOperator, evaluator);

            TokenDefinition partial1 = new TokenDefinition(TokenType.TernaryOperator1, precedence, associativity, pattern1);
            TokenDefinition partial2 = new TokenDefinition(TokenType.TernaryOperator2, precedence, associativity, pattern2);

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

            AddTokenDefinition(partial1);
            AddTokenDefinition(partial2);
        }
Esempio n. 2
0
        private void AddTokenDefinition(TokenDefinition tokenDefinition, TokenEvaluator evaluator)
        {
            tokenDefinition.Evaluator = evaluator;

            TokenDefinition existing = _TokenDefinitions.Find(delegate(TokenDefinition td)
            {
                return(td.Pattern == tokenDefinition.Pattern && !string.IsNullOrEmpty(td.Pattern));
            });

            if (existing != null)
            {
                existing.Alternate = tokenDefinition;
            }
            else
            {
                _TokenDefinitions.Add(tokenDefinition);
            }
        }
Esempio n. 3
0
        internal Token(TokenDefinition tokenDefinition, string text)
        {
            _text            = text;
            _tokenDefinition = tokenDefinition;

            switch (tokenDefinition.Type)
            {
            case TokenType.TernaryOperator: NumTerms = 3; break;

            case TokenType.UnaryOperator: NumTerms = 1; break;

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

            if (_tokenDefinition.Alternate != null)
            {
                _alternate = new Token(_tokenDefinition.Alternate, text);
            }
        }
Esempio n. 4
0
 private void AddTokenDefinition(TokenDefinition tokenDefinition)
 {
     AddTokenDefinition(tokenDefinition, null);
 }