/// <summary>
 /// Initialize a new instance of <see cref="AlgorithmIterationStatement"/>
 /// </summary>
 /// <param name="initializationStatement">The statement that initialize the iteration</param>
 /// <param name="incrementStatement">The statement that define the incrementation</param>
 /// <param name="condition">The test expression of the iteration</param>
 /// <param name="conditionAfterBody">This value defines whether the test expression will be run before of after the execution of the iteration's body</param>
 /// <param name="statements">The statements in the iteration's body</param>
 public AlgorithmIterationStatement(AlgorithmStatement initializationStatement, AlgorithmStatement incrementStatement, AlgorithmExpression condition, bool conditionAfterBody = false, AlgorithmStatementCollection statements = null)
 {
     InitializationStatement = initializationStatement;
     IncrementStatement      = incrementStatement;
     Condition          = condition;
     ConditionAfterBody = conditionAfterBody;
     Statements         = statements ?? new AlgorithmStatementCollection();
 }
        /// <summary>
        /// Execute a statement
        /// </summary>
        /// <param name="statement">The statement to interpret</param>
        /// <returns>Returns True is the statement was a <see cref="AlgorithmReturnStatement"/></returns>
        internal bool RunStatement(AlgorithmStatement statement)
        {
            var returnStmt = false;

            switch (statement.DomType)
            {
            case AlgorithmDomType.ConditionStatement:
                var condition = new Condition(DebugMode, this, statement);
                condition.Execute();
                returnStmt = condition.ReturnOccured;
                break;

            case AlgorithmDomType.IterationStatement:
                var iteration = new Iteration(DebugMode, this, statement);
                iteration.Execute();
                returnStmt = iteration.ReturnOccured;
                break;

            case AlgorithmDomType.ReturnStatement:
                new Return(DebugMode, this, statement).Execute();
                returnStmt = true;
                break;

            case AlgorithmDomType.AssignStatement:
                new Assign(DebugMode, this, statement).Execute();
                break;

            case AlgorithmDomType.VariableDeclaration:
                new VariableDeclaration(DebugMode, this, statement).Execute();
                break;

            case AlgorithmDomType.ExpressionStatement:
                new ExpressionStatement(DebugMode, this, statement).Execute();
                break;

            case AlgorithmDomType.BreakpointStatement:
                new Breakpoint(DebugMode, this).Execute();
                break;

            default:
                ChangeState(this, new AlgorithmInterpreterStateEventArgs(new Error(new InvalidCastException($"Unable to find an interpreter for this statement : '{statement.GetType().FullName}'"), statement), GetDebugInfo()));
                break;
            }

            return(returnStmt);
        }
Esempio n. 3
0
 /// <summary>
 /// Initialize a new instance of <see cref="Assign"/>
 /// </summary>
 /// <param name="debugMode">Defines if the debug mode is enabled</param>
 /// <param name="parentInterpreter">The parent block interpreter</param>
 /// <param name="statement">The algorithm statement</param>
 internal Assign(bool debugMode, BlockInterpreter parentInterpreter, AlgorithmStatement statement)
     : base(debugMode, parentInterpreter, statement)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Initialize a new instance of <see cref="VariableDeclaration"/>
 /// </summary>
 /// <param name="debugMode">Defines if the debug mode is enabled</param>
 /// <param name="parentInterpreter">The parent block interpreter</param>
 /// <param name="statement">The algorithm statement</param>
 public VariableDeclaration(bool debugMode, BlockInterpreter parentInterpreter, AlgorithmStatement statement)
     : base(debugMode, parentInterpreter, statement)
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Initialize a new instance of <see cref="Return"/>
 /// </summary>
 /// <param name="debugMode">Defines if the debug mode is enabled</param>
 /// <param name="parentInterpreter">The parent block interpreter</param>
 /// <param name="statement">The algorithm statement</param>
 public Return(bool debugMode, BlockInterpreter parentInterpreter, AlgorithmStatement statement)
     : base(debugMode, parentInterpreter, statement)
 {
 }
Esempio n. 6
0
 /// <summary>
 /// Initialize a new instance of <see cref="ExpressionStatement"/>
 /// </summary>
 /// <param name="debugMode">Defines if the debug mode is enabled</param>
 /// <param name="parentInterpreter">The parent block interpreter</param>
 /// <param name="statement">The algorithm statement</param>
 public ExpressionStatement(bool debugMode, BlockInterpreter parentInterpreter, AlgorithmStatement statement)
     : base(debugMode, parentInterpreter, statement)
 {
 }
Esempio n. 7
0
 /// <summary>
 /// Initialize a new instance of <see cref="InterpretStatement"/>
 /// </summary>
 /// <param name="debugMode">Defines if the debug mode is enabled</param>
 /// <param name="parentInterpreter">the parent <see cref="BlockInterpreter"/></param>
 /// <param name="statement">the algorithm statement</param>
 internal InterpretStatement(bool debugMode, BlockInterpreter parentInterpreter, AlgorithmStatement statement)
     : base(debugMode)
 {
     ParentInterpreter = parentInterpreter;
     Statement         = statement;
 }