コード例 #1
0
ファイル: Form1.cs プロジェクト: joynere/Favo
        //Event Handler for the "Run" item in the MenuStrip, compiles and runs the program
        private void RunToolStripMenuItemClick(object sender, EventArgs e)
        {
            waitingForInput = false;

            StepByStep = false;
            UpdateCodelines();
            errorBox.Text = "";

            try
            {
                rM       = new RegisterMachine(textEditorBox.Text.Split('\n').ToList(), ifMode);
                compiled = true;

                RegisterMachine.ReturnType T = RegisterMachine.ReturnType.RUNNING;

                // Execute code until end or input/output command
                while (T != RegisterMachine.ReturnType.END)
                {
                    T = rM.ExecuteRegisterMachine(ref OutputString);
                    // Show output if asked for
                    if (T == RegisterMachine.ReturnType.OUTPUT)
                    {
                        errorBox.Text = OutputString;
                    }

                    // Set register machine to "wait"-state and request input
                    if (T == RegisterMachine.ReturnType.INPUT)
                    {
                        UpdateLabels();
                        UpdateDataGridView();
                        waitingForInput       = true;
                        inputTextBox.ReadOnly = false;
                        inputTextBox.Enabled  = true;
                        inputTextBox.Text     = "Waiting for Input";
                        return;
                    }
                }
            }
            catch (Exception exception)
            {
                errorBox.Text = exception.Message;
            }

            UpdateLabels();
            UpdateDataGridView();

            rM.ResetState();
        }
コード例 #2
0
        //Event Handler for the "Run" item in the MenuStrip, compiles and runs the program
        private void RunToolStripMenuItemClick(object sender, System.EventArgs e)
        {
            errorBox.Text = "";

            try
            {
                // TODO: IMPLEMENT OPTIMISATION (compiled bool)!!!
                rM       = new RegisterMachine(textEditorBox.Text.Split('\n').ToList());
                compiled = true;
                rM.ExecuteRegisterMachine(false);
            }
            catch (Exception exception)
            {
                errorBox.Text = exception.Message;
            }

            UpdateLabels();
            UpdateDataGridView();

            rM.ResetState();
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: joynere/Favo
        //manages input/output prompt
        private void InputTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (waitingForInput)
                {
                    waitingForInput = false;

                    InputString           = inputTextBox.Text;
                    inputTextBox.ReadOnly = false;
                    inputTextBox.Enabled  = true;
                    textEditorBox.Focus();
                    inputTextBox.Text = "No input required";
                    if (StepByStep)
                    {
                        try
                        {
                            Highlight();
                            RegisterMachine.ReturnType T = rM.ExecuteRegisterMachine(ref InputString);
                            if (T == RegisterMachine.ReturnType.OUTPUT)
                            {
                                errorBox.Text = InputString;
                            }
                            if (T == RegisterMachine.ReturnType.INPUT)
                            {
                                UpdateLabels();
                                UpdateDataGridView();
                                waitingForInput   = true;
                                inputTextBox.Text = "Waiting for Input";
                                return;
                            }
                            if (T == RegisterMachine.ReturnType.END)
                            {
                                UpdateLabels();
                                UpdateDataGridView();
                                errorBox.Text = "Program execution finished!";

                                rM.ResetState();
                                return;
                            }
                        }
                        catch (Exception exc)
                        {
                            errorBox.Text = exc.Message;
                        }
                    }
                    else
                    {
                        try
                        {
                            RegisterMachine.ReturnType T = rM.ExecuteRegisterMachine(ref InputString);
                            if (T == RegisterMachine.ReturnType.OUTPUT)
                            {
                                errorBox.Text = InputString;
                            }
                            if (T == RegisterMachine.ReturnType.INPUT)
                            {
                                UpdateLabels();
                                UpdateDataGridView();
                                waitingForInput   = true;
                                inputTextBox.Text = "Waiting for Input";
                                return;
                            }
                            while (T != RegisterMachine.ReturnType.END)
                            {
                                T = rM.ExecuteRegisterMachine(ref OutputString);
                                if (T == RegisterMachine.ReturnType.OUTPUT)
                                {
                                    errorBox.Text = OutputString;
                                }
                                if (T == RegisterMachine.ReturnType.INPUT)
                                {
                                    waitingForInput   = true;
                                    inputTextBox.Text = "Waiting for Input";
                                    UpdateLabels();
                                    UpdateDataGridView();
                                    return;
                                }
                                if (T == RegisterMachine.ReturnType.END)
                                {
                                    UpdateLabels();
                                    UpdateDataGridView();
                                    errorBox.Text = "Program execution finished!";

                                    rM.ResetState();
                                    return;
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            errorBox.Text = exception.Message;
                        }

                        UpdateLabels();
                        UpdateDataGridView();

                        rM.ResetState();
                    }
                }
            }
        }