Inheritance: System.Windows.Forms.Form
コード例 #1
0
ファイル: frRun.cs プロジェクト: Eola/PSint
 public frRun(frMain form)
 {
     form1 = form;
     InitializeComponent();
 }
コード例 #2
0
ファイル: Classes.cs プロジェクト: LuckyGeck/PSint
        /// <summary>
        /// This method Runs the function.
        /// </summary>
        /// <param name="frmain1">Link to the main form.</param>
        /// <returns>If this function has return value, it returns this value.</returns>
        public string Run(frMain frmain1)
        {
            bool bBreak = false;
            bool bEndIfSearch = false;
            bool bEndWhile = false;

            for (int n = 0; n < code.Length; n++)
            {
                Application.DoEvents();

                if (frmain1.bStartBreaking)
                {
                    break;
                }

                String s = code[n];
                s.Trim();

                if (s != "")
                {
                    if ((s[0] == '#') || (s[0] == '='))
                    {
                        string cmd;
                        string param = "";
                        if (s.IndexOf(' ') >= 0)
                        {
                            cmd = s.Substring(0, s.IndexOf(' '));
                            param = s.Substring(s.IndexOf(' ') + 1);
                        }
                        else
                            cmd = s;

                        switch (cmd.ToLower())
                        {
                            case "#while":
                                nWhileStack.Add(n);
                                param = frmain1.processBlanks(param, this);
                                if (!bEndWhile) //if we must process this if
                                {
                                    if (!frmain1.processLogicalSeq(param, this)) // param=>false
                                    {
                                        bEndWhile = true;
                                    }
                                }
                                break;
                            case "#endwhile":
                                if (bEndWhile)
                                {
                                    nWhileStack.Remove(nWhileStack.Max());
                                    if (nWhileStack.Count == 0)
                                    {
                                        bEndWhile = false;
                                    }
                                }
                                else
                                {
                                    n = nWhileStack.Max() - 1;
                                    nWhileStack.Remove(nWhileStack.Max());
                                }
                                break;
                            case "#if":
                                nIfStack.Add(n);
                                param = frmain1.processBlanks(param, this);
                                if (!bEndIfSearch) //if we must process this if
                                {
                                    if (!frmain1.processLogicalSeq(param, this)) // param=>false
                                    {
                                        bEndIfSearch = true;
                                    }
                                }
                                break;
                            case "#endif":
                                if (nIfStack.Count != 0)
                                {
                                    nIfStack.Remove(nIfStack.Max());
                                    if (nIfStack.Count == 0)
                                    {
                                        bEndIfSearch = false;
                                    }
                                }
                                else
                                {
                                    frmain1.Error("#endif doesn't have an #if to close it!", n + 1);
                                }
                                break;
                            case "#return":
                                if (bEndIfSearch) break;
                                sReturn = frmain1.execCmd(cmd, param, this);
                                break;
                            case "#goto":
                                if (bEndIfSearch) break;
                                int nLine = Convert.ToInt32(param.Trim().Split(' ')[0]);
                                if (nLine > code.Length)
                                {
                                    frmain1.Error("Unreachable line - " + nLine.ToString(), n + 1);
                                    bBreak = true;
                                }
                                else
                                {
                                    n = nLine - 2;
                                }
                                break;
                            default:
                                if ((bEndIfSearch)||(bEndWhile)) break;
                                frmain1.execCmd(cmd, param, this);
                                break;
                        }
                        if (bBreak) break;

                    }
                    else
                    {
                        frmain1.Error("Unknown operator", n + 1);
                        // stop running
                        break;
                    }
                }

            }
            return sReturn;
        }