Ejemplo n.º 1
0
        // Event Handler for StepByStep ToolStripMenuItem, executes one line of code per click
        private void StepByStepToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                // Don't compile twice if code is already compiled
                if (!compiled)
                {
                    errorBox.Text = "";
                    rM            = new RegisterMachine(textEditorBox.Text.Split('\n').ToList());
                    compiled      = true;
                }

                Highlight();

                // Check if there are more steps available or end of code is reached
                if (rM.ExecuteOneStep() == false)
                {
                    UpdateLabels();
                    UpdateDataGridView();
                    errorBox.Text = "Program execution finished!";

                    rM.ResetState();
                }
                else
                {
                    UpdateLabels();
                    UpdateDataGridView();
                }
            }
            catch (Exception exc)
            {
                errorBox.Text = exc.Message;
            }
        }
Ejemplo n.º 2
0
        // Event Handler for StepByStep ToolStripMenuItem, executes one line of code per click
        private void StepByStepToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!waitingForInput)
            {
                StepByStep = true;
                try
                {
                    // Don't compile twice if code is already compiled
                    if (!compiled)
                    {
                        errorBox.Text = "";
                        rM            = new RegisterMachine(textEditorBox.Text.Split('\n').ToList(), ifMode);
                        compiled      = true;
                    }

                    Highlight();

                    // Check if there are more steps available or end of code is reached
                    RegisterMachine.ReturnType T = rM.ExecuteOneStep(ref OutputString);

                    switch (T)
                    {
                    case RegisterMachine.ReturnType.OUTPUT:
                        errorBox.Text = OutputString;
                        break;

                    case RegisterMachine.ReturnType.INPUT:
                        UpdateLabels();
                        UpdateDataGridView();
                        waitingForInput       = true;
                        inputTextBox.ReadOnly = false;
                        inputTextBox.Enabled  = true;
                        inputTextBox.Text     = "Waiting for Input";
                        return;

                    case RegisterMachine.ReturnType.END:
                        UpdateLabels();
                        UpdateDataGridView();
                        errorBox.Text = "Program execution finished!";

                        rM.ResetState();
                        break;

                    default:
                        UpdateLabels();
                        UpdateDataGridView();
                        break;
                    }
                }
                catch (Exception exc)
                {
                    errorBox.Text = exc.Message;
                }
            }
        }