Beispiel #1
0
        private void запускСканераToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ResultField.Text = "";
            String          inputText = CodeField.Text;
            Lexer           lexer     = new Lexer();
            List <Terminal> terminals = lexer.Find(inputText);

            foreach (Terminal terminal in terminals)
            {
                if (terminal.GetCode() >= 1 && terminal.GetCode() <= 4)
                {
                    ResultField.Text += terminal.GetCode() + " - ключевое слово - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 5)
                {
                    ResultField.Text += terminal.GetCode() + " - идентификатор - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() >= 6 && terminal.GetCode() <= 7)
                {
                    ResultField.Text += terminal.GetCode() + " - ключевое слово - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 8)
                {
                    ResultField.Text += terminal.GetCode() + " - разделитель - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 9)
                {
                    ResultField.Text += terminal.GetCode() + " - оператор присваивания - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 10)
                {
                    ResultField.Text += terminal.GetCode() + " - строка - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 11)
                {
                    ResultField.Text += terminal.GetCode() + " - символ - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 12)
                {
                    ResultField.Text += terminal.GetCode() + " - целое без знака - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 13)
                {
                    ResultField.Text += terminal.GetCode() + " - конец оператора - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 14)
                {
                    ResultField.Text += terminal.GetCode() + " - конец файла - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
                else if (terminal.GetCode() == 15)
                {
                    ResultField.Text += terminal.GetCode() + " - недопустимый символ - " + terminal.GetStr() + " - с " + terminal.GetStartIdx() + " по " + terminal.GetFinalIdx() + " символ \n";
                }
            }
        }