Esempio n. 1
0
        public WhileBlock(Queue <string> commands, State state, IIntreperter intreperter)
        {
            _intreperter = intreperter;
            _predicate   = commands.Dequeue();
            _commands    = new Queue <string>(commands);

            _blocks       = BlockGenerator.Generate(commands, state, intreperter).ToArray();
            _state        = state;
            _blockIndex   = 0;
            _currentBlock = null;
            _isFinished   = false;
            _predicateMet = null;
        }
Esempio n. 2
0
        public IfBlock(Queue <string> commandsIf, Queue <string> commandsElse, State state, IIntreperter intreperter)
        {
            _intreperter = intreperter;
            _predicate   = commandsIf.Dequeue();
            // dequeue first line
            if (commandsElse.Count > 0)
            {
                commandsElse.Dequeue();
            }

            _blocksIf   = BlockGenerator.Generate(commandsIf, state, intreperter);
            _blocksElse = BlockGenerator.Generate(commandsElse, state, intreperter);
        }
Esempio n. 3
0
        public StateMachine(string filePath)
        {
            Queue <string> commands = new Queue <string>();
            string         line     = "";

            _state      = new State();
            _totalLines = 0;

            IIntreperter intreperter = new VSSLIntreperter(_state);

            using (StreamReader reader = new StreamReader(filePath))
            {
                while ((line = reader.ReadLine()) != null)
                {
                    commands.Enqueue(line.ToUpper().Trim());
                }
            }

            _blocks       = BlockGenerator.Generate(commands, _state, intreperter);
            _currentBlock = null;
        }
Esempio n. 4
0
        public void NextStep()
        {
            if (_predicateMet is null)
            {
                _predicateMet = _intreperter.EvaluatePrecondition(_predicate);
                Console.WriteLine(_predicate + "\t" + _predicateMet);
            }

            if (_isFinished || _predicateMet == false)
            {
                return;
            }

            if (_currentBlock is null)
            {
                _currentBlock = _blocks[_blockIndex];
            }

            _currentBlock.NextStep();

            if (_currentBlock.IsFinished())
            {
                _currentBlock = null;
                _blockIndex++;

                if (_blockIndex == _blocks.Length)
                {
                    if (_intreperter.EvaluatePrecondition(_predicate) == false)
                    {
                        _isFinished = true;
                    }
                    else
                    {
                        _blockIndex = 0;
                        Queue <string> q = new Queue <string>(_commands);
                        _blocks = BlockGenerator.Generate(q, _state, _intreperter).ToArray();
                    }
                }
            }
        }