Esempio n. 1
0
 /// <summary>
 /// Проверяет, влючена ли буква в данный алфавит.
 /// </summary>
 /// <param name="findLatter">буква</param>
 /// <returns></returns>
 public bool Contains(Letter findLatter)
 {
     foreach (Letter letter in Letters)
     {
         if (letter == findLatter) return true;
     }
     return false;
 }
Esempio n. 2
0
        public static Machine Deserialize(string fileName)
        {
            Machine machine = new Machine();
            XmlDocument xml = new XmlDocument();
            xml.Load(fileName);
            XmlElement xmlMachine = xml["machine"];

            var states = xmlMachine["States"];
            foreach (XmlElement xmlState in states)
            {
                State state = new State();
                var attributes = xmlState.Attributes;
                state.Name = attributes[0].Value;
                state.IsLast = Convert.ToBoolean(attributes[1].Value);
                machine.States.Add(state);
            }

            var letters = xmlMachine["Alphabet"];
            foreach (XmlElement xmlLetter in letters)
            {
                Letter letter = new Letter();
                var attributes = xmlLetter.Attributes;
                letter.Name = attributes[0].Value;
                letter.Description = attributes[1].Value;
                machine.Alphabet.Letters.Add(letter);
            }

            var functions = xmlMachine["Functions"];
            foreach (XmlElement xmlFunction in functions)
            {
                Function function = new Function();
                var attributes = xmlFunction.Attributes;
                function.Name = attributes[0].Value;
                function.From = machine.States.Where(n => n.Name == attributes[1].Value).ToList()[0];
                function.To = machine.States.Where(n => n.Name == attributes[2].Value).ToList()[0];
                function.Letter = machine.Alphabet.Letters.Where(n => n.Name == attributes[3].Value).ToList()[0];
                machine.Functions.Add(function);
            }

            try
            {
                var firstState = xmlMachine.LastChild;
                var stateName = firstState.Attributes[0].Value;
                machine.FirstState = machine.States.Where(n => n.Name == stateName).ToList()[0];
            }
            catch
            {
                machine.FirstState = null;
            }

            return machine;
        }
Esempio n. 3
0
        private void AddNewLetter(object sender, EventArgs e)
        {
            try
            {
                string letterName = LetterName.Text;
                string letterDescription = LetterDescription.Text;
                Letter letter = new Letter(letterName, letterDescription);
                machine.Alphabet.AddNewLetter(letter);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка!");
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Добавляет новую букву в алфавит.
 /// </summary>
 /// <param name="letter">буква</param>
 public void AddNewLetter(Letter newLetter)
 {
     if (newLetter.Name.Length > 0)
     {
         foreach (Letter letter in letters)
         {
             if (letter == newLetter) throw new ArgumentException("Такая буква уже есть!");
         }
         letters.Add(newLetter);
     }
     else
     {
         throw new ArgumentException("Таконе название не допустимо!");
     }
 }
Esempio n. 5
0
        public void removeLetter(Letter letter)
        {
            for (int i = 0; i < functions.Count; i++)
            {
                if (functions[i].Letter == letter)
                {
                    removeFunction(functions[i]);
                    i--;
                }

            }
            alphabet.Letters.Remove(letter);
        }
Esempio n. 6
0
 public Function(string name, State from, State to, Letter letter)
 {
     this.name = name;
     this.from = from;
     this.to = to;
     this.letter = letter;
 }
Esempio n. 7
0
 public Function()
 {
     this.name = "";
     this.from = new State();
     this.to = new State();
     this.letter = new Letter();
 }