Ejemplo n.º 1
0
        public void Evaluate(IEnumerable <object> statements)
        {
            BeginScope();

            foreach (var statement in statements)
            {
                if (statement is Branch)
                {
                    Branch branch = (Branch)statement;

                    var branchCommand = new BranchCommand(branch.Left, branch.Right);
                    branchCommand.Run(this);
                }
                else if (statement is EndBranch)
                {
                    var endBranchCommand = new EndBranchCommand();
                    endBranchCommand.Run(this);
                }

                /* Todo: This breaks the pattern because we can't roll
                 *  up these commands into a list before looping through to run them.
                 */
                else if (SkipLines)
                {
                    var doNothingCommand = new DoNothingCommand();
                    doNothingCommand.Run(this);
                }

                else if (statement is CreateVariable)
                {
                    var createVariable = (CreateVariable)statement;

                    var createVariableCommand = new CreateVariableCommand(createVariable.Name,
                                                                          createVariable.Value);

                    createVariableCommand.Run(this);
                }
                else if (statement is Assignment)
                {
                    var assignment = (Assignment)statement;

                    var assignmentCommand = new AssignmentCommand(assignment.Name,
                                                                  assignment.Value);

                    assignmentCommand.Run(this);
                }
                else if (statement is MethodCall)
                {
                    var methodCall = (MethodCall)statement;

                    var methodCallCommand = new MethodCallCommand("print",
                                                                  methodCall.Arguments);

                    methodCallCommand.Run(this);
                }
            }

            EndScope();
        }
Ejemplo n.º 2
0
        protected override bool DoResolve(ScriptingContext context)
        {
            if (Argument.IndexOf ('=') > 0) {
                assign = new AssignmentCommand (Argument);
                return assign.Resolve (context);
            }

            return base.DoResolve (context);
        }