示例#1
0
        private void state8(CharChain chain)
        {
            char next = chain.GetNext();

            if (next == '0')
            {
                state = 11;
            }
            else if (next >= '1' && next <= '9')
            {
                state = 9;

                int digit = ((int)next) - ((int)'0');
                result = result * 10 + digit;
            }
            else if (next == '-')
            {
                state = 10;

                isNegative = true;
            }
            else if (next == '_')
            {
                state = 12;

                skip = true;
            }
            else
            {
                throw new Exception("Обнаружен символ: '" + charView(next) + "', ожидалась цифра.");
            }
        }
示例#2
0
        private void state9(CharChain chain)
        {
            char next = chain.GetNext();

            if (next >= '0' && next <= '9')
            {
                state = 9;

                int digit = ((int)next) - ((int)'0');
                result = result * 10 + digit;
            }
            else if (next == '\n' || next == '\0')
            {
                state = 13;

                if (isNegative)
                {
                    result *= -1;
                }
                isNegative = false;
            }
            else
            {
                throw new Exception("Обнаружен символ: '" + charView(next) + "', ожидался перенос строки или конец файла.");
            }
        }
示例#3
0
        private void state5(CharChain chain)
        {
            char next = chain.GetNext();

            if (next >= '0' && next <= '9')
            {
                state = 5;

                int digit = ((int)next) - ((int)'0');
                secondNumber = secondNumber * 10 + digit;
            }
            else if (next == '=')
            {
                state = 8;

                if (isNegative)
                {
                    secondNumber *= -1;
                }
                isNegative = false;
            }
            else
            {
                throw new Exception("Обнаружен символ: '" + charView(next) + "', ожидалось '='.");
            }
        }
示例#4
0
        private void state4(CharChain chain)
        {
            char next = chain.GetNext();

            if (next == '0')
            {
                state = 7;
            }
            else if (next >= '1' && next <= '9')
            {
                state = 5;

                int digit = ((int)next) - ((int)'0');
                secondNumber = secondNumber * 10 + digit;
            }
            else if (next == '-')
            {
                state = 6;

                isNegative = true;
            }
            else
            {
                throw new Exception("Обнаружен символ: '" + charView(next) + "', ожидалась цифра.");
            }
        }
示例#5
0
        private void state1(CharChain chain)
        {
            char next = chain.GetNext();

            if (next >= '0' && next <= '9')
            {
                state = 1;

                int digit = ((int)next) - ((int)'0');
                firstNumber = firstNumber * 10 + digit;
            }
            else if (isOperation(next))
            {
                state = 4;

                operation = next;
                if (isNegative)
                {
                    firstNumber *= -1;
                }
                isNegative = false;
            }
            else
            {
                throw new Exception("Обнаружен символ: '" + charView(next) + "', ожидалась операция.");
            }
        }
示例#6
0
        private void state12(CharChain chain)
        {
            char next = chain.GetNext();

            if (next == '\n' || next == '\0')
            {
                state = 13;
            }
            else
            {
                throw new Exception("Обнаружен символ : '" + charView(next) + "', ожидался перенос строки или конец файла.");
            }
        }
示例#7
0
        private void state7(CharChain chain)
        {
            char next = chain.GetNext();

            if (next == '=')
            {
                state = 8;
            }
            else
            {
                throw new Exception("Обнаружен символ: '" + charView(next) + "', ожидался '='.");
            }
        }
示例#8
0
        private void state3(CharChain chain)
        {
            char next = chain.GetNext();

            if (isOperation(next))
            {
                state = 4;

                operation = next;
            }
            else
            {
                throw new Exception("Обнаружен символ: '" + charView(next) + "', ожидался знак операции.");
            }
        }
示例#9
0
        private void state10(CharChain chain)
        {
            char next = chain.GetNext();

            if (next >= '1' && next <= '9')
            {
                state = 9;

                int digit = ((int)next) - ((int)'0');
                result = result * 10 + digit;
            }
            else
            {
                throw new Exception("Обнаружен символ: '" + charView(next) + "', ожидалась цифра.");
            }
        }
示例#10
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            CharChain chain   = new CharChain(CodeField.Text);
            Automat   automat = new Automat();
            bool      result  = false;

            int correct = 0;
            int wrong   = 0;

            for (int i = 1; i <= 5; i++)
            {
                try
                {
                    result = automat.Check(chain);
                }
                catch (Exception ex)
                {
                    ResultField.Text += "\r\nПример №" + i.ToString() + " " + ex.Message;
                    return;
                }

                if (result)
                {
                    correct++;
                }
                else
                {
                    wrong++;
                }
            }

            char next = chain.GetNext();

            if (next != '\0')
            {
                ResultField.Text += "\r\nВведено больше 5 примеров.";
                return;
            }

            ResultField.Text += "\r\nВерно: " + correct.ToString() + ", неверно: " + wrong.ToString();
        }
示例#11
0
        private bool tryStop()
        {
            char next = chain.Next().Char;

            if (next == '\0' || next == ';')
            {
                chain.GetNext();
                state = 13;
                return(true);
            }

            return(false);
        }