コード例 #1
0
        public void Compile()
        {
            LastInputValue = int.MaxValue;
            int commandIterator = 0;

            this.poliz = PolizAnalyzer.sharedAnalyzer.Poliz;
            for (int i = 0; i < this.poliz.Count; i++)
            {
                PolizAnalyzer.sharedAnalyzer.LogLexems("Poliz", this.poliz);
                if (poliz[i].Command == "=")
                {
                    Out.Log(Out.State.LogDebug, "Will change value for ID " + poliz[commandIterator].Command +
                            " (old value " + poliz[commandIterator].Value + ")");
                    poliz[commandIterator].Value = CalculateExpression(new List <Lexem>(this.poliz),
                                                                       commandIterator + 1, i - 1);
                    Out.Log(Out.State.LogDebug, "Did change value for ID " + poliz[commandIterator].Command +
                            " (new value " + poliz[commandIterator].Value + ")");
                    commandIterator = i + 1;
                }

                else if (poliz[i].Command == "output")
                {
                    for (int j = commandIterator; j < i; j++)
                    {
                        if (poliz[j].Command[0] == '"')
                        {
                            Out.Log(Out.State.ApplicationOutput, poliz[j].Command.
                                    Replace("\"", "").Replace("_", " ").Replace("   ", " ").Remove(0, 1));
                        }
                        else if (poliz[j].isCONST())
                        {
                            Out.Log(Out.State.ApplicationOutput, poliz[j].Command);
                        }
                        else
                        {
                            Out.Log(Out.State.ApplicationOutput, poliz[j].Command + " = " + poliz[j].Value);
                        }
                    }
                    commandIterator = i + 1;
                }

                else if (poliz[i].Command == "input")
                {
                    for (int j = commandIterator; j < i; j++)
                    {
                        Gtk.Application.Invoke(delegate {
                            InputIDDialog dialog = new InputIDDialog();
                            dialog.Title         = "Введите значение " + poliz[j].Command;
                            dialog.Response     += DidConfirmInputDialog;
                            dialog.Run();
                            dialog.Destroy();
                        });
                        // Synchronize threads. Better use Mutex or Semaphore //
                        while (LastInputValue == int.MaxValue)
                        {
                            Thread.Sleep(100);
                        }
                        poliz[j].Value = LastInputValue;
                        LastInputValue = int.MaxValue;
                    }
                    commandIterator = i + 1;
                }

                else if (poliz[i].Key == PolizOperarionsList.kLexemKeyUPL)                 // if
                {
                    bool ok = CalculateLogicalExpression(commandIterator, i - 2);
                    if (false == ok)                     // false. go to "else" block
                    {
                        string destinationLabel = poliz[i - 1].Command;
                        i = LabelFinder.PositionCloseLabel(poliz, destinationLabel);
                    }
                    commandIterator = i + 1;
                }

                else if (poliz[commandIterator].Key == PolizOperarionsList.kLexemKeyLabelStart &&
                         poliz[commandIterator + 1].Key == PolizOperarionsList.kLexemKeyBP)                 // unused "else" block
                {
                    string destinationLabel = poliz[commandIterator].Command;
                    i = LabelFinder.PositionCloseLabel(poliz, destinationLabel);
                    commandIterator = i + 1;
                }

                else if (poliz[i].Key == PolizOperarionsList.kLexemKeyLabelEnd)                 // endif
                {
                    i++;
                    commandIterator = i;
                }
            }
            PolizAnalyzer.sharedAnalyzer.LogLexems("Poliz", this.poliz);
            Out.Log(Out.State.ApplicationOutput, "\n" +
                    "============================\n" +
                    "Приложение отработало корректно\n" +
                    "Результаты вычислений приблизительные, поскольку программа " +
                    "работает только с целыми числами");
        }
コード例 #2
0
        void DidConfirmInputDialog(object obj, ResponseArgs args)
        {
            InputIDDialog dialog = (InputIDDialog)obj;

            LastInputValue = dialog.Result();
        }