Example #1
0
        public void Build()
        {
            DFAReader dfaReader = new DFAReader();
            List<State> dfaStates = dfaReader.ReadStates();
            List<StateTransition> dfaTransitions = dfaReader.ReadTransitions();

            startState = dfaStates[0];

            foreach (var transition in dfaTransitions)
            {
                State state1 = dfaStates[transition.State1ID];
                State state2 = dfaStates[transition.State2ID];

                foreach (var ch in transition.TransitionChars)
                {
                    if (!stateTransitionTable.ContainsKey(state1))
                        stateTransitionTable.Add(state1, new Dictionary<char, State>());

                    stateTransitionTable[state1].Add(ch, state2);
                }
            }
        }
Example #2
0
        public List<State> ReadStates()
        {
            string[] statesFile = File.ReadAllLines(statesFilePath);

            List<State> states = new List<State>();

            foreach (var line in statesFile)
            {
                string[] data = line.Split(' ');
                State state = new State()
                {
                    ID = int.Parse(data[0]),
                    IsFinal = (data[1] == "t" ? true : false)
                };

                if (state.IsFinal == true) state.MatchedSymbol = data[2];

                states.Add(state);
            }

            return states;
        }