Exemplo n.º 1
0
        private void Step(object sender, EventArgs e)
        {
            if (!codeReader.isCodeReady)
            {
                Preparation();
                codeReader.code = ts.Text;
                tempCode        = ts.Text;
            }

            string tempName = "", tempCommand = "", tempArg1 = "", tempArg2 = "";

            //DoLineMain(ref tempName, ref tempCommand, ref tempArg1, ref tempArg2);


            string lineCode = "";

            try
            {
                lineCode = codeReader.readNext();
            } catch (EofException ex)
            {
                end = true;
                return;
            }

            if (lineCode.isEmpty())
            {
                return;
            }

            LineData lineData = lineParser.parse(lineCode);


            try
            {
                Command command = commandDefiner.define(lineData);
                if (codeReader.currentLine == 0)
                {
                    if (command == null || !(command is StartCommand))
                    {
                        throw new ArgumentException("Не обнаружена директива START");
                    }
                    else
                    {
                        stackScope.Push("main");
                    }
                }
                if (command == null)
                {
                    if (lineData.args.get(1)?.isNotEmpty() == true)
                    {
                        throw new ArgumentException("Неправильный формат объявления директивы");
                    }
                    if (lineData.lable?.isNotEmpty() == true && Config.getInstance().macroMode)
                    {
                        throw new ArgumentException("Макропроцессор не поддерживает макровызовы внутри макроопределений");
                    }
                    else if (lineData.lable?.isNotEmpty() == true && !Config.getInstance().macroMode)
                    {
                    }
                    else
                    {
                        throw new ArgumentException($"Макропроцессор не поддерживает директиву.");
                    }
                }

                command.execute(tableNMacro, tableV, tableMacro, tom);
                if (command is CallMacroCommand)
                {
                    CodeReader macroCodeReader = new CodeReader();
                    macroCodeReader.codeLinesList = tableMacro.startFrom((command as CallMacroCommand).startMacro).map(item => item.Body);
                    while (macroCodeReader.hasNext())
                    {
                        LineData macroLineData = lineParser.parse(macroCodeReader.readNext());
                        Command  macroCommand  = commandDefiner.define(macroLineData);

                        if (config.stackIf.isNotEmpty() && !(macroCommand is ElseCommand || macroCommand is EndifCommand))
                        {
                            if (config.stackIf.isNotEmpty() && !config.stackIf.Peek())
                            {
                                continue;
                            }
                        }

                        if (macroCommand is WhileCommand)
                        {
                            config.whileIndex = macroCodeReader.currentLine - 1;
                        }

                        if (config.stackWhile.isNotEmpty() && config.stackWhile.Peek())
                        {
                            if (macroCommand is EndwCommand)
                            {
                                macroCodeReader.currentLine = config.whileIndex;
                                continue;
                            }
                        }
                        else if (config.stackWhile.isNotEmpty() && !config.stackWhile.Peek() && !(macroCommand is EndwCommand))
                        {
                            continue;
                        }

                        macroCommand.execute(tableNMacro, tableV, tableMacro, tom);
                    }
                }

                if (CheckError())
                {
                    return;
                }
                lineCount++;
                SelectLine();
                Renew();
                return;
            }
            catch (Exception ex)
            {
                err.AppendText(ex.Message);
                err.AppendText(" Строка №" + (codeReader.currentLine + 1));
                err.AppendText("\n" + ex.StackTrace);
                bstep.Enabled = false;
                bpass.Enabled = false;
                save.Enabled  = true;
                open.Enabled  = true;
            }
        }
Exemplo n.º 2
0
 public void Preparation()
 {
     ts.ReadOnly  = true;
     open.Enabled = false;
     codeReader   = new CodeReader();
 }