Пример #1
0
        public override void Run(BasicStep command)
        {
            var atr = command.AllTheRest;
            var ptrs = atr.Split(new []{"FROM"},StringSplitOptions.RemoveEmptyEntries);
            atr = ptrs[1];
            var varName = ptrs[0].Trim();
            ptrs = atr.Split(new[] { "TO" }, StringSplitOptions.RemoveEmptyEntries);
            var start = int.Parse( ptrs[0].Trim());
            var endName = ptrs[1].Trim();
            int end;

            if (!interpreter.Variables.TryGetValue(endName, out end))
            {
                end = int.Parse(endName);
            }

            if(interpreter.Loop == null){
                interpreter.Loop = new ForLoop
                {
                    from = start,
                    to = end,
                    stepNumber = command.Number,
                    VarName = varName
                };
                interpreter.Variables[varName] = start;
            }
            else
            {
                var varVal = interpreter.Variables[varName];
                varVal++;
                interpreter.Variables[varName] = varVal;
                if (varVal > end)
                    interpreter.FinishLoop();
            }
        }
Пример #2
0
 public override void Run(BasicStep command)
 {
     var parts = command.AllTheRest.Split('=');
     var variableName = parts[0].Trim();
     var valueOfVar = int.Parse(parts[1].Trim());
     interpreter.Variables[variableName] = valueOfVar;
 }
Пример #3
0
 public void Compile()
 {
     foreach (var item in program)
     {
         var bs = new BasicStep(item);
         steps.Add(bs);
     }
 }
Пример #4
0
 public void Run(BasicStep command)
 {
     var atr = command.AllTheRest;
     foreach (var item in interpreter.Variables)
     {
         atr = atr.Replace("{" + item.Key + "}", item.Value.ToString());
     }
     Console.WriteLine(atr);
 }
Пример #5
0
        public override void Run(BasicStep command)
        {
            var parts = command.AllTheRest.Split(' ');
            var x = parts[0];
            var y = parts[1];

            var xv = interpreter.Variables[x];
            xv *= interpreter.Variables[y];
            interpreter.Variables[x] = xv;
        }
Пример #6
0
 public abstract void Run(BasicStep command);
Пример #7
0
 public override void Run(BasicStep command)
 {
     interpreter.Next();
 }