Пример #1
0
        /// <summary>
        /// Executes the GET command.
        /// </summary>
        public void Execute()
        {
            if (!_runEnvironment.CurrentLine.LineNumber.HasValue)
            {
                throw new Exceptions.IllegalDirectException();
            }

            var         variableReference = _expressionEvaluator.GetLeftValue();
            var         newChar           = _teletypeWithPosition.ReadChar();
            Accumulator newValue;

            if (variableReference.IsString)
            {
                newValue = new Accumulator(newChar.ToString());
            }
            else
            {
                if ("+-E.\0".Contains(newChar.ToString()))
                {
                    newChar = '0';
                }

                if (newChar < '0' || newChar > '9')
                {
                    throw new Exceptions.SyntaxErrorException();
                }

                newValue = new Accumulator((double)(newChar - '0'));
            }

            variableReference.SetValue(newValue);
        }
Пример #2
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);
            }
        }
Пример #3
0
        /// <summary>
        /// Executes the LET command.
        /// </summary>
        public void Execute()
        {
            var variableReference = _expressionEvaluator.GetLeftValue();
            var token             = _runEnvironment.CurrentLine.NextToken();

            if (token.Seperator != TokenType.Equal)
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var newValue = _expressionEvaluator.GetExpression();

            variableReference.SetValue(newValue);
        }
Пример #4
0
        /// <summary>
        /// Executes the READ command.
        /// </summary>
        public void Execute()
        {
            var    variableReferences = new List <VariableReference>();
            IToken token;

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

            _runEnvironment.CurrentLine.PushToken(token);
            _runEnvironment.DataErrorLine = _dataStatementReader.CurrentDataLine;
            _dataStatementReader.ReadInputParser.ReadVariables(variableReferences);
            _runEnvironment.DataErrorLine = null;
        }