コード例 #1
0
        public void ExecuteForEachCommand()
        {
            IExpression addToX = new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("b"), new VariableExpression("a"));
            ICommand setX = new SetVariableCommand("a", addToX);
            IExpression values = new ConstantExpression(new int [] { 1, 2, 3 } );

            ForEachCommand foreachcmd = new ForEachCommand("b", values, setX);

            Context context = new Context();

            context.SetValue("a", 0);

            foreachcmd.Execute(context);

            Assert.AreEqual(6, context.GetValue("a"));
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: tario/AjScript-migrated
        private ICommand ParseForInCommand()
        {
            string name = this.ParseName();
            bool isvar = false;

            if (name == "var")
            {
                name = this.ParseName();
                isvar = true;
            }

            this.Parse(TokenType.Name, "in");
            IExpression values = this.ParseExpression();
            this.Parse(TokenType.Separator, ")");
            ICommand command = this.ParseCommand();

            ICommand forcmd = new ForEachCommand(name, values, command);

            if (!isvar)
                return forcmd;

            // TODO review if var command should be hoisted
            ICommand cmds = new CompositeCommand(new List<ICommand>() { new VarCommand(name), forcmd });

            return cmds;
        }