Beispiel #1
0
        private void ExecuteStatements()
        {
            ResetInterpreter();
            InvokeDispatcher(() =>
            {
                _codeViewer.Document.Blocks.Clear();
                _codeViewer.AppendOutput("Running script...");
            });

            if (string.IsNullOrEmpty(Code))
            {
                return;
            }

            var tokens = new AphidLexer(Code).GetTokens();

            List <Components.Aphid.Parser.Expression> ast = null;

            try
            {
                ast = new AphidParser(tokens).Parse();
            }
            catch (AphidParserException ex)
            {
                InvokeDispatcher(() =>
                                 _codeViewer.AppendParserException(Code, ex));

                return;
            }

            try
            {
                _interpreter.Interpret(ast);
            }
            catch (AphidRuntimeException ex)
            {
                InvokeDispatcher(() =>
                                 _codeViewer.AppendException(Code, "Runtime error", ex));

                return;
            }
            catch (AphidParserException ex)
            {
                InvokeDispatcher(() =>
                                 _codeViewer.AppendParserException(Code, ex));

                return;
            }
            catch (Exception ex)
            {
                InvokeDispatcher(() =>
                                 _codeViewer.AppendException(Code, "Internal error", ex));
            }

            UpdateVariables();
            ExecuteWatchExpressions();

            InvokeDispatcher(() =>
            {
                _codeViewer.AppendOutput("Done");
                _codeViewer.ScrollToEnd();
            });
        }