Ejemplo n.º 1
0
 public bool Equals(NfaState <TLetter> other)
 {
     if (ReferenceEquals(other, this))
     {
         return(true);
     }
     return((other != null) && Equals(this.AcceptId, other.AcceptId) && this.matchTransitions.Equals(other.matchTransitions) && this.epsilonTransitions.SetEqual(other.epsilonTransitions, IdComparer <NfaState <TLetter> > .Default));
 }
Ejemplo n.º 2
0
        private NfaState <TLetter> Create(SymbolId?acceptSymbol = null, int precedence = 0)
        {
            var id    = new Id <NfaState <TLetter> >(this.states.Count);
            var state = new NfaState <TLetter>(id, acceptSymbol, precedence);

            this.states.Add(id, state);
            return(state);
        }
Ejemplo n.º 3
0
 public Nfa(IReadOnlyDictionary <Id <NfaState <TLetter> >, NfaState <TLetter> > states, NfaState <TLetter> startState, NfaState <TLetter> endState)
 {
     this.States     = states.Values;
     this.StartState = startState;
     this.EndState   = endState;
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        NfaState <TLetter> IRegexVisitor <TLetter, NfaState <TLetter>, NfaState <TLetter> > .Match(RxMatch <TLetter> node, NfaState <TLetter> context)
        {
            var target = this.Create();

            foreach (var range in node.Letters)
            {
                context.AddMatchTransition(range, target);
            }
            return(target);
        }
Ejemplo n.º 6
0
 NfaState <TLetter> IRegexVisitor <TLetter, NfaState <TLetter>, NfaState <TLetter> > .Empty(RxEmpty <TLetter> node, NfaState <TLetter> context)
 {
     return(context);
 }
Ejemplo n.º 7
0
 NfaState <TLetter> IRegexVisitor <TLetter, NfaState <TLetter>, NfaState <TLetter> > .Concatenation(RxConcatenation <TLetter> node, NfaState <TLetter> context)
 {
     return(node.Right.Visit(this, node.Left.Visit(this, context)));
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        NfaState <TLetter> IRegexVisitor <TLetter, NfaState <TLetter>, NfaState <TLetter> > .Accept(RxAccept <TLetter> node, NfaState <TLetter> context)
        {
            var target = this.Create(node.Symbol, node.AcceptPrecedence);

            node.Inner.Visit(this, context).AddEpsilonTransition(target);
            return(target);
        }
Ejemplo n.º 10
0
 public NfaBuilder()
 {
     this.startState = this.Create();
 }
Ejemplo n.º 11
0
 public void AddMatchTransition(Range <TLetter> match, NfaState <TLetter> target)
 {
     this.matchTransitions.Add(match, target);
 }
Ejemplo n.º 12
0
 public void AddEpsilonTransition(NfaState <TLetter> target)
 {
     this.epsilonTransitions.Add(target);
 }