示例#1
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            // TAB is only valid inside a PRINT command.
            if (!(interpreter.CurrentCommandToken is PrintToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            // Make sure next token is a '('.
            if (tokenMarker.Token == null || !(tokenMarker.Token is OpenParenToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var valueToken = interpreter.ExpressionEvaluator.Evaluate(tokenMarker);

            if (!(valueToken is NumericValueToken numericValueToken))
            {
                throw new Exceptions.TypeMismatchException();
            }

            // Make sure last token in expression ended in a ')'.
            if (!(tokenMarker.PeekPrev() is CloseParenToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var newColumn = numericValueToken.IntValue;

            if (newColumn < 0 || newColumn > 255)
            {
                throw new Exceptions.IllegalQuantityException();
            }

            // If the current cursor column is already beyond the new column, don't move the cursor
            if (interpreter.Console.CursorColumn > newColumn)
            {
                return;
            }

            interpreter.Console.Tab(newColumn);
        }
示例#2
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            // SPC is only valid inside a PRINT command
            if (!(interpreter.CurrentCommandToken is PrintToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            // Make sure next token is a '('.
            if (tokenMarker.Token == null || !(tokenMarker.Token is OpenParenToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var valueToken = interpreter.ExpressionEvaluator.Evaluate(tokenMarker);

            if (!(valueToken is NumericValueToken numericValueToken))
            {
                throw new Exceptions.TypeMismatchException();
            }

            // Make sure last token in expression ended in a ')'.
            if (!(tokenMarker.PeekPrev() is CloseParenToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var value = numericValueToken.IntValue;

            if (value < 0 || value > 255)
            {
                throw new Exceptions.IllegalQuantityException();
            }

            interpreter.Console.Spc(value);
        }