Ejemplo n.º 1
0
        static Script BuildScriptTree(List <IScriptCommand> commands)
        {
            Stack <List <IScriptCommand> > context = new Stack <List <IScriptCommand> >();

            foreach (IScriptCommand command in commands)
            {
                if (context.Count() == 0)
                {
                    context.Push(new List <IScriptCommand>());
                }
                ;
                if (command.Type.Equals("basic") &&
                    command.GetType() != typeof(LoopStartCommand) &&
                    command.GetType() != typeof(LoopEndCommand))
                {
                    context.Peek().Add(command);
                }
                if (command.GetType() == typeof(LoopStartCommand))
                {
                    List <IScriptCommand> newContext = new List <IScriptCommand>();
                    newContext.Add(command);
                    context.Push(newContext);
                }
                if (command.GetType() == typeof(LoopEndCommand))
                {
                    List <IScriptCommand> currentContext = context.Pop();
                    LoopStartCommand      loopStart      = (LoopStartCommand)currentContext[0];
                    currentContext.RemoveAt(0);
                    LoopCommand loop = new LoopCommand(loopStart, currentContext, (LoopEndCommand)command);
                    context.Peek().Add(loop);
                }
            }
            return(new Script(context.Pop()));
        }
Ejemplo n.º 2
0
        private static IScriptCommand BuildComplexCommand(string CommandName, params object[] args)
        {
            switch (CommandName)
            {
            case "loop":
                LoopStartCommand      start    = (LoopStartCommand)args[0];
                List <IScriptCommand> commands = (List <IScriptCommand>)args[1];
                LoopEndCommand        end      = (LoopEndCommand)args[2];
                return(new LoopCommand(start, commands, end));

            case "script":
                List <IScriptCommand> scriptsCommands = (List <IScriptCommand>)args[0];
                return(new CompositeCommand(scriptsCommands));

            case "composite":
                List <IScriptCommand> compositeCommands = (List <IScriptCommand>)args[0];
                return(new CompositeCommand(compositeCommands));
            }
            return(null);
        }
Ejemplo n.º 3
0
 public void VisitLoopStart(LoopStartCommand Start)
 {
     System.Console.WriteLine("loop-start " + Start.Loops);
 }
Ejemplo n.º 4
0
 public LoopCommand(LoopStartCommand start, List <IScriptCommand> commands, LoopEndCommand end) : base(commands)
 {
     Start = start;
     End   = end;
 }
 private void SerializeIf(LoopStartCommand cmd)
 {
     sb.AppendFormat("loop_start_if {0}\n", cmd.LoopCount);
 }