예제 #1
0
        private RegexTerm VisitRegexTermNode(IInternalTreeNode internalNode)
        {
            RegexFactor factor = null;
            RegexTerm   term   = null;

            for (var c = 0; c < internalNode.Children.Count; c++)
            {
                var child = internalNode.Children[c];
                if (child.NodeType != TreeNodeType.Internal)
                {
                    continue;
                }
                var childInternalNode            = child as IInternalTreeNode;
                var childInternalNodeSymbolValue = childInternalNode.Symbol.Value;

                if (RegexGrammar.Factor == childInternalNodeSymbolValue)
                {
                    factor = VisitRegexFactorNode(childInternalNode);
                }
                else if (RegexGrammar.Term == childInternalNodeSymbolValue)
                {
                    term = VisitRegexTermNode(childInternalNode);
                }
            }
            if (term is null)
            {
                return(new RegexTerm(factor));
            }

            return(new RegexTermFactor(factor, term));
        }
        private static INfa Factor(RegexFactor factor)
        {
            var atomNfa = Atom(factor.Atom);

            switch (factor.NodeType)
            {
            case RegexNodeType.RegexFactor:
                return(atomNfa);

            case RegexNodeType.RegexFactorIterator:
                var regexFactorIterator = factor as RegexFactorIterator;
                switch (regexFactorIterator.Iterator)
                {
                case RegexIterator.ZeroOrMany:
                    return(KleeneStar(atomNfa));

                case RegexIterator.OneOrMany:
                    return(KleenePlus(atomNfa));

                case RegexIterator.ZeroOrOne:
                    return(Optional(atomNfa));
                }
                break;
            }
            throw new InvalidOperationException("Unrecognized regex factor");
        }
예제 #3
0
 public RegexTermFactor(RegexFactor factor, RegexTerm term)
     : base(factor)
 {
     Term      = term;
     _hashCode = ComputeHashCode();
 }
예제 #4
0
 public RegexTerm(RegexFactor factor)
 {
     Factor    = factor;
     _hashCode = ComputeHashCode();
 }