Esempio n. 1
0
        NfaState <TLetter> IRegexVisitor <TLetter, NfaState <TLetter>, NfaState <TLetter> > .Quantified(RxQuantified <TLetter> node, NfaState <TLetter> context)
        {
            for (var i = 0; i < node.Min; i++)
            {
                context = node.Inner.Visit(this, context);
            }
            var target = context;

            if (node.Max.HasValue)
            {
                for (var i = node.Min; i < node.Max.Value; i++)
                {
                    target = node.Inner.Visit(this, context);
                    context.AddEpsilonTransition(target);
                    context = target;
                }
            }
            else
            {
                // kleene closure
                var innerStart = this.Create();
                context.AddEpsilonTransition(innerStart);
                target = this.Create();
                innerStart.AddEpsilonTransition(target);
                var innerEnd = node.Inner.Visit(this, innerStart);
                innerEnd.AddEpsilonTransition(innerStart);
            }
            return(target);
        }
Esempio n. 2
0
        NfaState <TLetter> IRegexVisitor <TLetter, NfaState <TLetter>, NfaState <TLetter> > .Alternation(RxAlternation <TLetter> node, NfaState <TLetter> context)
        {
            var left = this.Create();

            context.AddEpsilonTransition(left);
            var right = this.Create();

            context.AddEpsilonTransition(right);
            var target = this.Create();

            node.Left.Visit(this, left).AddEpsilonTransition(target);
            node.Right.Visit(this, right).AddEpsilonTransition(target);
            return(target);
        }