S
S
svgboyzs2020-10-26 16:13:02
.NET
svgboyzs, 2020-10-26 16:13:02

String validation through the Stateless Framework. How to implement?

Hello! I wrote a DFA model program using the stateless framework, the entered string after a character-by-character check should remain in its initial state. I can't figure out how to link a string and a DFA model. For example, you can take a string whose elements will go through the entire model and remain in q0

string isValue = "11010";


The model itself:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Stateless;
using Stateless.Graph;

namespace Lib1
{
    enum State
    {
        Q0,
        Q1,
        Q2
    }

    enum Input
    {
        One = 1,
        Zero = 0
    }

    class Program
    {

        static void Main(string[] args)
        {
            string isValue = "11010";
            var stateMachine = new StateMachine<State, Input>(State.Q0);

            stateMachine.Configure(State.Q0)
                .Permit(Input.Zero, State.Q2)
                .PermitReentry(Input.One);

            stateMachine.Configure(State.Q1)
                .Permit(Input.Zero, State.Q0)
                .PermitReentry(Input.One);

            stateMachine.Configure(State.Q2)
               .Permit(Input.One, State.Q1)
               .PermitReentry(Input.Zero);

          //  stateMachine.Fire(Input.Zero);

            string graph = UmlDotGraph.Format(stateMachine.GetInfo());
            Console.WriteLine(graph);
        }
    }
}


Console output:

1hI_3i1IHi4.jpg

Model itself:

XMZ7mjX-7qA.jpg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question