示例#1
0
 private static Expression ParseExpression(Tree tree, ref Token token, Token[] tokens, ref int index, char terminator)
 {
     var node = new Expression();
     
     while(ParseTerms(node, tree, ref token, tokens, ref index, terminator)) { }
     
     return node;
 }
示例#2
0
        private static bool ParseTerms(Expression node, Tree tree, ref Token token, Token[] tokens, ref int index, char terminator)
        {
            var term = ParseTerm(tree, ref token, tokens, ref index);

            node.Terms.Add(term);

            if (token == null || token is Operator && token.Value.Equals(terminator.ToString(CultureInfo.InvariantCulture)))
            {
                return false;
            }

            while (IsExpressionOperator(token))
            {
                if (IsAlternation(token))
                {
                    node.Operators.Add(new Alternation { Value = token.Value });
                }
                if (IsConcatenation(token))
                {
                    node.Operators.Add(new Concatenation { Value = token.Value });
                }
                if (IsRepeat(token))
                {
                    node.Operators.Add(new Repeat { Value = token.Value });
                }
                if (IsExcept(token))
                {
                    node.Operators.Add(new Except { Value = token.Value });
                }
                token = NextToken(tokens, ref index);
            }

            return true;
        }