Beispiel #1
0
        /// <summary>
        /// Executes the statements and returns the result.
        /// </summary>
        /// <param name="statements">The statements to be executed.</param>
        /// <returns>The execution result of <paramref name="statements"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="statements"/> is <see langword="null"/>, or contains <see langword="null"/>.</exception>
        /// <exception cref="RuntimeException">An exception occurred during the execution of the statements.</exception>
        public ExecuteResult ExecuteStatements(StatementCollection statements)
        {
            if (statements == null || statements.Contains(null))
            {
                throw new ArgumentNullException();
            }
            if (Labels == null)
            {
                Labels = new Dictionary <string, LabelStatement>();
            }
            HoistingExecuteStatements(statements);
            ExecuteResult flow;

            for (int i = 0; i < statements.Count; i++)
            {
                CancellationToken.ThrowIfCancellationRequested();
                flow = ExecuteStatement(statements[i]);
label:
                if (flow.FlowControl == FlowControl.Goto)
                {
                    var go = (string)flow.Data;
                    if (Labels.ContainsKey(go))
                    {
                        i    = statements.IndexOf(Labels[go]);
                        flow = ExecuteStatement(Labels[go]);
                        goto label;
                    }
                    else
                    {
                        return(flow);
                    }
                }
                else if (flow.FlowControl == FlowControl.Break ||
                         flow.FlowControl == FlowControl.Return ||
                         flow.FlowControl == FlowControl.Continue)
                {
                    return(flow);
                }
            }
            Labels.Clear();
            return(ExecuteResult.Next);
        }