public override List <Transition> GetAutomaton(ref int i, ref List <Transition> ListTransitions, ref List <State> ListStates, ref List <Alphabet> ListAlphabets) { List <Transition> transitions_got_by_parsed_repetition = new List <Transition>(); State initial = new State($"S{i}"); initial.IsInitial = true; i++; ListStates.Add(initial); List <Transition> transitions_got_by_parsing_leftexpression = Left_Expression.GetAutomaton(ref i, ref ListTransitions, ref ListStates, ref ListAlphabets); State final = new State($"S{i}"); final.IsFinal = true; i++; ListStates.Add(final); State left_left_state = transitions_got_by_parsing_leftexpression.Find(x => x.GetLeftState().IsInitial).GetLeftState(); State right_left_state = transitions_got_by_parsing_leftexpression.Find(x => x.GetRightState().IsFinal).GetRightState(); left_left_state.IsInitial = false; right_left_state.IsFinal = false; Transition transition1 = new Transition("_", null); transition1.SetLeftState(initial); transition1.SetRightState(left_left_state); transitions_got_by_parsed_repetition.Add(transition1); ListTransitions.Add(transition1); Transition transition2 = new Transition("_", null); transition2.SetLeftState(initial); transition2.SetRightState(final); transitions_got_by_parsed_repetition.Add(transition2); ListTransitions.Add(transition2); Transition transition3 = new Transition("_", null); transition3.SetLeftState(right_left_state); transition3.SetRightState(left_left_state); transitions_got_by_parsed_repetition.Add(transition3); ListTransitions.Add(transition3); transitions_got_by_parsed_repetition.AddRange(transitions_got_by_parsing_leftexpression); Transition transition4 = new Transition("_", null); transition4.SetLeftState(right_left_state); transition4.SetRightState(final); transitions_got_by_parsed_repetition.Add(transition4); ListTransitions.Add(transition4); return(transitions_got_by_parsed_repetition); }
public override List <Transition> GetAutomaton(ref int i, ref List <Transition> ListTransitions, ref List <State> ListStates, ref List <Alphabet> ListAlphabets) { List <Transition> transitions_got_by_parsing_concatenation = new List <Transition>(); List <Transition> transitions_got_by_parsing_leftexpression = Left_Expression.GetAutomaton(ref i, ref ListTransitions, ref ListStates, ref ListAlphabets); List <Transition> transitions_got_by_parsing_rightexpression = Right_Expression.GetAutomaton(ref i, ref ListTransitions, ref ListStates, ref ListAlphabets); State final_left = transitions_got_by_parsing_leftexpression.Find(x => x.GetRightState().IsFinal).GetRightState(); final_left.IsFinal = false; State initial_right = transitions_got_by_parsing_rightexpression.Find(x => x.GetLeftState().IsInitial).GetLeftState(); List <Transition> transitions_contain_initial_right = transitions_got_by_parsing_rightexpression.FindAll(x => x.GetLeftState() == initial_right); foreach (Transition transition in transitions_contain_initial_right) { transition.SetLeftState(final_left); } ListStates.Remove(initial_right); transitions_got_by_parsing_concatenation.AddRange(transitions_got_by_parsing_leftexpression); transitions_got_by_parsing_concatenation.AddRange(transitions_got_by_parsing_rightexpression); return(transitions_got_by_parsing_concatenation); }