public void ShowProgram(PsudoProgram prog)
        {
            this.program = prog;
            this.drawingPanel.Roots.Clear();

            this.drawingPanel.Controls.Clear();
            FlowChartItemControl item = new FlowChartItemControl(program.MainMethod.Name);

            item.IsStartEndProgram = true;

            this.drawingPanel.Controls.Add(item);
            CreateChildren(program.MainMethod.Instructions, item);

            item.Location = new Point(500, 10);

            Rectangle treeBounds = item.GetTreeBounds();
            int       newLeft    = item.Left + treeBounds.Left * -1 + 20;
            int       newTop     = item.Top + treeBounds.Top * -1 + 20;

            item.Location = new Point(newLeft, newTop);

            this.drawingPanel.Roots.Add(item);
            this.drawingPanel.UpdateTreeBounds();

            this.Invalidate();
            item.DisableAutoPlacement();
        }
Beispiel #2
0
        private bool Compile()
        {
            if (this.dirtyFlag)
            {
                if (MessageBox.Show("Save file before compiling?", "Save File?", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.SaveCode();
                }
            }
            this.Status             = "Compiling Code...";
            this.outputTextBox.Text = "";
            PsudoCompiler compiler = new PsudoCompiler(this.codeRichTextBox.Text);

            if (compiler.CheckSyntax())
            {
                if (compiler.Compile())
                {
                    this.program     = compiler.program;
                    this.compileInfo = compiler;
                    this.PrintCompilerData(compiler);
                    this.Status = "Compile Successful";
                    return(true);
                }
                else
                {
                    this.AppendText("Compile Failed\n\n", Color.Red);
                    this.Status = "Compile Failed";
                    foreach (CompileError error in compiler.Errors)
                    {
                        this.AppendText(
                            string.Format("Line {0}: {1}\n", error.Line, error.Details),
                            Color.Red);
                    }
                }
            }
            else
            {
                this.AppendText("Invalid Syntax\n\n", Color.Red);
                this.Status = "Invalid Syntax";
                foreach (CompileError error in compiler.scanner.errors)
                {
                    this.AppendText(
                        string.Format("Line {0}: {1}\n", error.Line, error.Details),
                        Color.Red);
                }
            }
            return(false);
        }
Beispiel #3
0
        void program_ProgramComplete(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(this.program_ProgramComplete), sender, e);
            }
            else
            {
                this.variableGrid.Refresh();
                this.AppendText("\nProgram Completed", Color.Yellow);
                // this.rightPaneSplitter.Visible = false;
                // this.viewsTabControl.SelectedTab = this.editCodePage;
                this.codeLinesList.SelectedIndex = -1;
                this.IsRunning = false;

                this.program = null;
            }
        }
Beispiel #4
0
        private void viewsTabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.rightPaneSplitter.Visible = (this.viewsTabControl.SelectedTab == this.runtimePage);

            if (this.viewsTabControl.SelectedTab == this.runtimePage)
            {
                this.outputTextBox.Focus();
            }
            else if (this.viewsTabControl.SelectedTab == this.flowChartPage)
            {
                if (this.Compile())
                {
                    this.flowChartViewerControl1.ShowProgram(this.program);
                    this.program = null;
                }
                else
                {
                    this.viewsTabControl.SelectedTab = this.editCodePage;
                }
            }
        }
        public bool Compile()
        {
            try
            {
                this.program = new PsudoProgram();

                foreach (PsudoClassInfo pClassInfo in this.scanner.classInfo)
                {
                    PsudoClass pClass = new PsudoClass(pClassInfo.Name);
                    this.program.Classes.Add(pClass.Name, pClass);

                    var classMethods = this.scanner.methodInfo.FindAll(
                        item => item.StartLine > pClassInfo.StartLine && item.StartLine < pClassInfo.EndLine);

                    foreach (PsudoMethodInfo mInfo in classMethods)
                    {
                        pClass.Methods.Add(mInfo.Name, CompileMethod(mInfo, pClassInfo, pClass));
                    }

                    var classVars = this.scanner.variableInfo.FindAll(
                        item => item.Line > pClassInfo.StartLine && item.Line < pClassInfo.EndLine && !item.Processed);

                    foreach (PsudoVariableInfo vInfo in classVars)
                    {
                        vInfo.ParentClass = pClassInfo;
                        vInfo.Processed   = true;
                        pClass.ClassVariables.Add(vInfo.Name, CreateVariable(vInfo));
                    }
                }

                var globalMethods = this.scanner.methodInfo.FindAll(item => !item.Processed);

                foreach (PsudoMethodInfo mInfo in globalMethods)
                {
                    this.program.GlobalMethods.Add(mInfo.Name, CompileMethod(mInfo, null, null));
                }

                if (this.program.GlobalMethods.Count == 1)
                {
                    this.program.MainMethod = this.program.GlobalMethods.Values.First();
                }
                else
                {
                    if (this.program.GlobalMethods.ContainsKey("main"))
                    {
                        this.program.MainMethod = this.program.GlobalMethods["main"];
                    }
                    else if (this.program.GlobalMethods.ContainsKey("mainline"))
                    {
                        this.program.MainMethod = this.program.GlobalMethods["mainline"];
                    }
                    else if (this.program.GlobalMethods.ContainsKey("start"))
                    {
                        this.program.MainMethod = this.program.GlobalMethods["start"];
                    }
                    else
                    {
                        // We don't have a designated Main. Will have to be chosen later.
                        this.program.MainMethod = null;
                    }
                }

                var globalVars = this.scanner.variableInfo.FindAll(item => !item.Processed);

                foreach (PsudoVariableInfo vInfo in globalVars)
                {
                    vInfo.Processed = true;
                    this.program.GlobalVariables.Add(vInfo.Name, CreateVariable(vInfo));
                }

                return(this.Errors.Count == 0);
            }
            catch (Exception e)
            {
                this.Errors.Add(new CompileError(e.Message, -1));
                return(false);
            }
        }