예제 #1
0
        /// <summary>
        /// Executes the INPUT command.
        /// </summary>
        public void Execute()
        {
            var variableReferences = new List <VariableReference>();

            // Not valid in immediate mode.
            if (!_runEnvironment.CurrentLine.LineNumber.HasValue)
            {
                throw new Exceptions.IllegalDirectException();
            }

            // Set the prompt.
            _prompt = "?";
            var token = _runEnvironment.CurrentLine.NextToken();

            if (token.TokenClass == TokenClass.String)
            {
                _prompt = token.Text;
                if (_runEnvironment.CurrentLine.NextToken().Seperator != TokenType.Semicolon)
                {
                    throw new Exceptions.SyntaxErrorException();
                }
            }
            else
            {
                _runEnvironment.CurrentLine.PushToken(token);
            }

            do
            {
                variableReferences.Add(_expressionEvaluator.GetLeftValue());
                token = _runEnvironment.CurrentLine.NextToken();
            }while (token.Seperator == TokenType.Comma);

            _runEnvironment.CurrentLine.PushToken(token);

            bool reenterInput = false;

            do
            {
                _firstLine = true;
                _readInputParser.Clear();
                try
                {
                    reenterInput = false;
                    _readInputParser.ReadVariables(variableReferences);
                }
                catch (Exceptions.SyntaxErrorException)
                {
                    _teletype.Write("?RENTER");
                    _teletype.Write(Environment.NewLine);
                    reenterInput = true;
                }
            }while (reenterInput);
            if (_readInputParser.HasExtraData)
            {
                _teletype.Write("?EXTRA IGNORED");
                _teletype.Write(Environment.NewLine);
            }
        }
예제 #2
0
        /// <summary>
        /// Lists a single line.
        /// </summary>
        /// <returns>returns false if last line printed.</returns>
        public bool Execute()
        {
            if (_currentLine != null)
            {
                if (_currentLine.LineNumber > _endLine)
                {
                    return(true);
                }

                _teletype.Write(_currentLine.ToString());
                _teletype.Write(Environment.NewLine);
                _currentLine = _programRepository.GetNextLine(_currentLine.LineNumber.Value);
            }

            return(_currentLine == null);
        }
 /// <summary>
 /// Prints a new line.
 /// </summary>
 public void NewLine()
 {
     _teletype.Write(Environment.NewLine);
     _currentPosition = 0;
 }