Exemple #1
0
        public void Execute(ExecutionState state)
        {
            IList list;

            if (expr is IListExpression)
            {
                list = ((IListExpression)expr).GetList(state);
            }
            else
            {
                list = expr.Evaluate(state, listToken) as IList;
                if (list == null)
                {
                    throw new InstructionExecutionException("\"" + listToken.Value + "\" doesn't contain a list of anything.", listToken);
                }
            }

            //if (state.HasVariable(iteratorToken.Value))
            //    throw new InstructionExecutionException("\"" + iteratorToken.Value + "\" already equates to something else. You should use a different word.", iteratorToken);
            foreach (object item in list)
            {
                state.Variables[iteratorToken.Value] = item;
                instructions.Execute(state);
            }
            state.Variables.Remove(iteratorToken.Value);
        }
Exemple #2
0
        public void Execute(ExecutionState state)
        {
            DateTime start = DateTime.Now;
            DateTime stop  = start.AddSeconds(15);

            while (true)
            {
                if (DateTime.Now > stop)
                {
                    throw new InstructionExecutionException("I have stopped the \"while\" loop because more than 15 seconds has passed, which means something has likely gone wrong.", token);
                }
                object val = expr.Evaluate(state, token);
                if (val == null)
                {
                    break;
                }
                if (BooleanExpression.True.Equals(val))
                {
                    list.Execute(state);
                }
                else
                {
                    break;
                }
            }
        }