예제 #1
0
 public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
 {
     if (!(tokenMarker.Token is StringValueToken stringValueToken))
     {
         throw new Exceptions.SyntaxErrorException();
     }
 }
예제 #2
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            var             variableNameToken = tokenMarker.Token as VariableNameToken;
            ValueTokenArray indicies          = null;

            if (variableNameToken == null)
            {
                throw new Exceptions.SyntaxErrorException();
            }

            if (tokenMarker.PeekNext() is OpenParenToken)
            {
                indicies = interpreter.ExpressionEvaluator.EvaluateVariableArrayAssignment(tokenMarker);
            }
            else
            {
                tokenMarker.MoveNext();
            }

            var equalsToken = tokenMarker.Token;

            if (!(equalsToken is Operators.EqualToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            if (tokenMarker.GetNextToken() == null)
            {
                throw new Exceptions.SyntaxErrorException();
            }

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

            interpreter.VariablesEnvironment.SetVariableValue(variableNameToken, indicies, result);
        }
예제 #3
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            // For an empty PRINT command, just output a writeline and return.
            if (tokenMarker.Token == null)
            {
                interpreter.Console.OutputTextWriter.WriteLine();
                return;
            }

            Token lastToken = null;

            while (tokenMarker.Token != null)
            {
                lastToken = tokenMarker.Token;
                switch (tokenMarker.Token)
                {
                case StringValueToken stringValueToken:
                case RealValueToken realValueToken:
                case IntegerValueToken integerValueToken:
                case UnaryMinusToken unaryMinusToken:
                case MinusToken minusToken:
                case PlusToken plusToken:
                case VariableNameToken variableToken:
                case FunctionToken functionToken:
                case FnToken userDefinedFunctionToken:
                case OpenParenToken openParenToken:
                    var result = interpreter.ExpressionEvaluator.Evaluate(tokenMarker);
                    WriteValue(interpreter, result);
                    break;

                case SemicolonToken semiColonToken:
                    tokenMarker.MoveNext();
                    break;

                case CommaToken commaToken:
                    MoveToNextTabMargin(interpreter);
                    tokenMarker.MoveNext();
                    break;

                case TabToken tabToken:
                    tokenMarker.MoveNext();
                    tabToken.Execute(interpreter, tokenMarker);
                    break;

                case SpcToken spcToken:
                    tokenMarker.MoveNext();
                    spcToken.Execute(interpreter, tokenMarker);
                    break;

                default:
                    throw new Exceptions.SyntaxErrorException();
                }
//                lastToken = tokenMarker.Token;
//                tokenMarker.MoveNext();
            }
            if (!((lastToken is SemicolonToken) || (lastToken is CommaToken)))
            {
                interpreter.Console.OutputTextWriter.WriteLine();
            }
        }
예제 #4
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            while (tokenMarker.Token != null)
            {
                if (!(tokenMarker.Token is VariableNameToken variableNameToken))
                {
                    throw new Exceptions.SyntaxErrorException();
                }

                if (!(tokenMarker.PeekNext() is OpenParenToken))
                {
                    throw new Exceptions.SyntaxErrorException();
                }

                var indicies = interpreter.ExpressionEvaluator.EvaluateVariableArrayAssignment(tokenMarker);
                interpreter.VariablesEnvironment.DimensionArrayVariable(variableNameToken, indicies);

                if (!(tokenMarker.Token is CommaToken))
                {
                    break;
                }

                tokenMarker.MoveNext();
            }
        }
예제 #5
0
        public static TokenMarker[] MeanSquareOrthogonalReferenceSystemOptimized(TokenMarker originalOrigin, TokenMarker originalXAxis, TokenMarker originalYAxis, TokenMarker originalData, float originToAxisDistance, int[] dataCoordinates)
        {
            TokenMarker[] result             = new TokenMarker[3];
            float[]       meanSquareSolution = new float[4];

            float ox = originalOrigin.Position.x, oy = originalOrigin.Position.y, xx = originalXAxis.Position.x, xy = originalXAxis.Position.y, yx = originalYAxis.Position.x, yy = originalYAxis.Position.y;

            meanSquareSolution[0] = (-ox - oy + (2 * xx) - xy - yx + (2 * yy)) / (originToAxisDistance * 4);
            meanSquareSolution[1] = -((-ox + oy - xx - (2 * xy) + (2 * yx) + yy) / (originToAxisDistance * 4));
            meanSquareSolution[2] = -((-(2 * ox) - xx - xy - yx + yy) / 4f);
            meanSquareSolution[3] = ((2 * oy) - xx + xy + yx + yy) / 4f;

            Vector2 newOrigin = new Vector2(meanSquareSolution[2],
                                            meanSquareSolution[3]);
            Vector2 newXAxis = new Vector2(originToAxisDistance * meanSquareSolution[0] + meanSquareSolution[2],
                                           originToAxisDistance * meanSquareSolution[1] + meanSquareSolution[3]);
            Vector2 newYAxis = new Vector2(-originToAxisDistance * meanSquareSolution[1] + meanSquareSolution[2],
                                           originToAxisDistance * meanSquareSolution[0] + meanSquareSolution[3]);

            result[0] = new TokenMarker(originalOrigin.Id, newOrigin, originalOrigin.State, MarkerType.Origin);
            result[1] = new TokenMarker(originalXAxis.Id, newXAxis, originalXAxis.State, MarkerType.XAxis);
            result[2] = new TokenMarker(originalYAxis.Id, newYAxis, originalYAxis.State, MarkerType.YAxis);



            return(result);
        }
예제 #6
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            string fileName;

            switch (tokenMarker.Token)
            {
            case StringValueToken stringValueToken:
                fileName = stringValueToken.Value;
                break;

            case VariableNameToken variableNameToken:
                var evalToken = interpreter.ExpressionEvaluator.Evaluate(tokenMarker);
                if (evalToken is StringValueToken evalStringToken)
                {
                    fileName = evalStringToken.Value;
                    break;
                }
                throw new Exceptions.SyntaxErrorException();

            default:
                throw new Exceptions.SyntaxErrorException();
            }

            interpreter.LoadFromFile(fileName);
        }
예제 #7
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            if (tokenMarker.Token != null)
            {
                throw new Exceptions.SyntaxErrorException();
            }

            interpreter.ClearAll();
        }
예제 #8
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            var variableNameTokens = new List <VariableNameToken>();

            while (tokenMarker.Token != null)
            {
                if (!(tokenMarker.Token is VariableNameToken variableNameToken))
                {
                    throw new Exceptions.SyntaxErrorException();
                }

                if (!((variableNameToken.VariableType == VariableValueType.IntegerNumber) ||
                      (variableNameToken.VariableType == VariableValueType.RealNumber)))
                {
                    throw new Exceptions.TypeMismatchException();
                }

                variableNameTokens.Add(variableNameToken);

                // Maybe add more variable names to the list
                if (tokenMarker.GetNextToken() is CommaToken)
                {
                    tokenMarker.MoveNext();
                    continue;
                }
            }

            if (interpreter.ForNextLoops.Count == 0)
            {
                throw new Exceptions.NextWithoutForException();
            }

            if (variableNameTokens.Count == 0)
            {
                ProcessForNextState(interpreter, interpreter.ForNextLoops.Peek());
                return;
            }

            int variableNameIndex = 0;

            while (variableNameIndex < variableNameTokens.Count)
            {
                if (interpreter.ForNextLoops.TryPeek(out ForNextLoopState forNextState) == false)
                {
                    throw new Exceptions.NextWithoutForException();
                }

                bool forNextLoopDone = ProcessForNextState(interpreter, forNextState, variableNameTokens[variableNameIndex]);
                if (!forNextLoopDone)
                {
                    return;
                }

                variableNameIndex += 1;
            }
        }
예제 #9
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            try
            {
                var returnMarker = interpreter.GosubMarkers.Pop();
//                returnMarker.MoveToNextStatement();
                interpreter.NextStatementMarker = returnMarker;
            }
            catch (InvalidOperationException)
            {
                throw new Exceptions.ReturnWithoutGosubException();
            }
        }
예제 #10
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            if (tokenMarker.Token != null)
            {
                throw new Exceptions.SyntaxErrorException();
            }

            if (interpreter.CurrentStatementMarker != null && interpreter.CurrentStatementMarker.Valid == false)
            {
                throw new Exceptions.CantContinueException();
            }

            interpreter.ContinueRun();
        }
예제 #11
0
        public override ValueToken Evaluate(Interpreter interpreter, ValueToken[] valueTokens)
        {
            // A separate expression evaluator is needed since the one created by the interpreter
            // has state unrelated to this statement's state.
            if (expressionEvaluator == null)
            {
                expressionEvaluator = new ExpressionEvaluator(interpreter);
            }

            interpreter.VariablesEnvironment.SetVariableValue(variableNameToken, valueTokens[0]);

            var marker = new TokenMarker(statement.Tokens);

            return(expressionEvaluator.Evaluate(marker));
        }
예제 #12
0
        /// <summary>
        /// Converts a series of TouchInputs present in a cluster to TokenMarkers with specific <see cref="MarkerType"/>
        /// </summary>
        /// <param name="orderedIndexes">Array of indexes ordered according to <see cref="MarkerType"/> </param>
        /// <param name="clusterPoints">Dictionary of TouchInputs present in a cluster</param>
        /// <returns>A dictionary of TokenMarkers with their ID as key</returns>
        public static Dictionary <int, TokenMarker> ConvertTouchInputToMarkers(int[] orderedIndexes, Dictionary <int, TouchInput> clusterPoints)
        {
            Dictionary <int, TokenMarker> result = new Dictionary <int, TokenMarker>();

            for (int i = 0; i < orderedIndexes.Length; i++)
            {
                TouchInput ti = clusterPoints[orderedIndexes[i]];

                // ordered index is organized:
                // [0] => Origin
                // [1] => XAxis
                // [2] => YAxis
                // [3] => Data

                switch (i)
                {
                case 0:
                {
                    TokenMarker tm = new TokenMarker(ti.Id, ti.Position, ti.State, MarkerType.Origin);
                    result.Add(tm.Id, tm);
                    break;
                }

                case 1:
                {
                    TokenMarker tm = new TokenMarker(ti.Id, ti.Position, ti.State, MarkerType.XAxis);
                    result.Add(tm.Id, tm);
                    break;
                }

                case 2:
                {
                    TokenMarker tm = new TokenMarker(ti.Id, ti.Position, ti.State, MarkerType.YAxis);
                    result.Add(tm.Id, tm);
                    break;
                }

                case 3:
                {
                    TokenMarker tm = new TokenMarker(ti.Id, ti.Position, ti.State, MarkerType.Data);
                    result.Add(tm.Id, tm);
                    break;
                }
                }
            }

            return(result);
        }
예제 #13
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);
        }
예제 #14
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            if (tokenMarker.Token == null)
            {
                interpreter.Run();
                return;
            }

            if (!(tokenMarker.Token is NumericValueToken numericValueToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            if (tokenMarker.PeekNext() != null)
            {
                throw new Exceptions.SyntaxErrorException();
            }

            interpreter.Run(numericValueToken.IntValue);
        }
예제 #15
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            if (!(tokenMarker.Token is ToToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            if (!(tokenMarker.GetNextToken() is NumericValueToken numberToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var gotoMarker = interpreter.CreateStatementMarker();

            if (gotoMarker.MoveToLine(numberToken.IntValue) == false)
            {
                throw new Exceptions.UndefinedStatementException();
            }

            interpreter.NextStatementMarker = gotoMarker;
        }
예제 #16
0
        /// <summary>
        /// Computes the closest orthogonal reference system to the one originally detected with a mean square solution
        /// </summary>
        /// <param name="originalOrigin">Originally detected Origin marker</param>
        /// <param name="originalXAxis">Originally detected X Axis marker</param>
        /// <param name="originalYAxis">Originally detected Y Axis marker</param>
        /// <param name="originToAxisDistance"> Distance between Origin marker and Axis markers</param>
        /// <returns>Array of TokenMarkers reppresdenting the closest orthgoanl reference system with respect to the specified one</returns>
        public static TokenMarker[] MeanSquareOrthogonalReferenceSystem(TokenMarker originalOrigin, TokenMarker originalXAxis, TokenMarker originalYAxis, float originToAxisDistance)
        {
            TokenMarker[] result = new TokenMarker[3];
            var           M      = Matrix <float> .Build;


            float[,] arrayA = { {                 0.0f,                  0.0f, 1.0f, 0.0f },
                                {                 0.0f,                  0.0f, 0.0f, 1.0f },
                                { originToAxisDistance,                  0.0f, 1.0f, 0.0f },
                                {                 0.0f, originToAxisDistance,  0.0f, 1.0f },
                                {                 0.0f, -originToAxisDistance, 1.0f, 0.0f },
                                { originToAxisDistance,                  0.0f, 0.0f, 1.0f } };

            float[,] arrayB = { { originalOrigin.Position.x },
                                { originalOrigin.Position.y },
                                { originalXAxis.Position.x  },
                                { originalXAxis.Position.y  },
                                { originalYAxis.Position.x  },
                                { originalYAxis.Position.y  } };

            var A = M.DenseOfArray(arrayA);
            var b = M.DenseOfArray(arrayB);

            var x = A.TransposeThisAndMultiply(A).Inverse() * A.TransposeThisAndMultiply(b);

            float[,] transformationMatrix = x.ToArray();

            Vector2 newOrigin = new Vector2(transformationMatrix[2, 0],
                                            transformationMatrix[3, 0]);
            Vector2 newXAxis = new Vector2(originToAxisDistance * transformationMatrix[0, 0] + transformationMatrix[2, 0],
                                           originToAxisDistance * transformationMatrix[1, 0] + transformationMatrix[3, 0]);
            Vector2 newYAxis = new Vector2(-originToAxisDistance * transformationMatrix[1, 0] + transformationMatrix[2, 0],
                                           originToAxisDistance * transformationMatrix[0, 0] + transformationMatrix[3, 0]);

            result[0] = new TokenMarker(originalOrigin.Id, newOrigin, originalOrigin.State, MarkerType.Origin);
            result[1] = new TokenMarker(originalXAxis.Id, newXAxis, originalXAxis.State, MarkerType.XAxis);
            result[2] = new TokenMarker(originalYAxis.Id, newYAxis, originalYAxis.State, MarkerType.YAxis);

            return(result);
        }
예제 #17
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            if (!(tokenMarker.Token is NumericValueToken lineNumberToken))
            {
                throw new Exceptions.UndefinedStatementException();
            }

            var currentMarker = interpreter.CopyCurrentStatementMarker();

            currentMarker.MoveToNextStatement();

            interpreter.GosubMarkers.Push(currentMarker);

            var gotoMarker = interpreter.CreateStatementMarker();

            if (gotoMarker.MoveToLine(lineNumberToken.IntValue) == false)
            {
                throw new Exceptions.UndefinedStatementException();
            }

            interpreter.NextStatementMarker = gotoMarker;
        }
예제 #18
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            if (tokenMarker.Token == null || !(tokenMarker.Token is NumericValueToken numberToken))
            {
                throw new Exceptions.UndefinedStatementException();
            }

            if (interpreter.InterpreterMode == InterpreterMode.Immmediate)
            {
                interpreter.WarmRun(numberToken.IntValue);
                return;
            }

            var gotoMarker = interpreter.CreateStatementMarker();

            if (gotoMarker.MoveToLine(numberToken.IntValue) == false)
            {
                throw new Exceptions.UndefinedStatementException();
            }

            interpreter.NextStatementMarker = gotoMarker;
        }
예제 #19
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);
        }
예제 #20
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            // Check to see if in direct mode

            if (!(tokenMarker.Token is FnToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }


            var userDefinedFunctionNameToken = tokenMarker.GetNextToken();

            if (!(userDefinedFunctionNameToken is VariableNameToken userDefinedNameToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            if (userDefinedNameToken.VariableType != VariableValueType.RealNumber)
            {
                throw new Exceptions.TypeMismatchException();
            }

            var openParenToken = tokenMarker.GetNextToken();

            if (!(openParenToken is OpenParenToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var parameterToken = tokenMarker.GetNextToken();

            if (!(parameterToken is VariableNameToken functionParameterToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var closeParenToken = tokenMarker.GetNextToken();

            if (!(closeParenToken is CloseParenToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            var equalsParenToken = tokenMarker.GetNextToken();

            if (!(equalsParenToken is Operators.EqualToken))
            {
                throw new Exceptions.SyntaxErrorException();
            }

            List <Token> userDefinedFunctionTokens = new List <Token>();

            while (tokenMarker.GetNextToken() != null)
            {
                userDefinedFunctionTokens.Add(tokenMarker.Token);
            }

            var userDefinedStatement = new Statement(userDefinedFunctionTokens);

            var userDefinedFunction = new Functions.UserDefinedFunction(functionParameterToken, userDefinedStatement);

            interpreter.VariablesEnvironment.CreateUserDefinedFunction(userDefinedNameToken, userDefinedFunction);
        }
예제 #21
0
 public virtual void Execute(RetroBASIC.Interpreter interpreter, TokenMarker tokenMarker)
 {
     throw new NotImplementedException();
 }
예제 #22
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            while (tokenMarker.Token != null)
            {
                ValueTokenArray indicies = null;

                if (!(tokenMarker.Token is VariableNameToken variableNameToken))
                {
                    throw new Exceptions.SyntaxErrorException();
                }

                if (tokenMarker.PeekNext() is OpenParenToken)
                {
                    indicies = interpreter.ExpressionEvaluator.EvaluateVariableArrayAssignment(tokenMarker);
                }
                else
                {
                    tokenMarker.MoveNext();
                }

                var valueToken = interpreter.ReadNextDataValue();
                if (valueToken == null)
                {
                    throw new Exceptions.OutOfDataException();
                }

                switch (variableNameToken.VariableType)
                {
                case VariableValueType.String:
                    break;

                case VariableValueType.RealNumber:
                    float realValue = 0;
                    var   success   = float.TryParse(((StringValueToken)valueToken).Value, out realValue);
                    if (success == false)
                    {
                        throw new Exceptions.TypeMismatchException();
                    }
                    valueToken = interpreter.TokensProvider.CreateRealValueToken(realValue);
                    break;

                case VariableValueType.IntegerNumber:
                    success = float.TryParse(((StringValueToken)valueToken).Value, out realValue);
                    if (success == false)
                    {
                        throw new Exceptions.TypeMismatchException();
                    }
                    // In Commodore BASIC, a READ of a number with a decimal into an integer number produces a zero.
                    int intValue = (int)Math.Abs(realValue);
                    if (realValue != intValue)
                    {
                        intValue = 0;
                    }

                    if (intValue < Int16.MinValue || intValue > Int16.MaxValue)
                    {
                        throw new Exceptions.OverflowException();
                    }

                    valueToken = interpreter.TokensProvider.CreateIntegerValueToken((Int16)intValue);
                    break;
                }

                interpreter.VariablesEnvironment.SetVariableValue(variableNameToken, indicies, valueToken);

                if (tokenMarker.Token == null)
                {
                    break;
                }

                if (!(tokenMarker.Token is CommaToken))
                {
                    throw new Exceptions.SyntaxErrorException();
                }

                tokenMarker.MoveNext();
                // The next token should now be a variable name token
            }
        }
예제 #23
0
 public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
 {
     throw new Exceptions.SyntaxErrorException();
 }
예제 #24
0
 public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
 {
     interpreter.BreakDetected();
 }
예제 #25
0
 public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
 {
     interpreter.DataStatementMarker.MoveTo(0);
 }
예제 #26
0
 public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
 {
     /* The REM command is just for comments. */
 }
예제 #27
0
 public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
 {
     throw new Exceptions.CommandNotSupportedException();
 }
예제 #28
0
 public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
 {
     // Nothing to see here. Move along.
 }
예제 #29
0
        public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
        {
            if (interpreter.InterpreterMode == InterpreterMode.Immmediate)
            {
                throw new Exceptions.IllegalDirectModeException();
            }

            var variableNameTokens = new List <(VariableNameToken, ValueTokenArray)>();

            while (tokenMarker.Token != null)
            {
                ValueTokenArray indicies = null;
                if (!(tokenMarker.Token is VariableNameToken variableNameToken))
                {
                    throw new Exceptions.SyntaxErrorException();
                }

                if (tokenMarker.PeekNext() is OpenParenToken)
                {
                    indicies = interpreter.ExpressionEvaluator.EvaluateVariableArrayAssignment(tokenMarker);
                }
                else
                {
                    tokenMarker.MoveNext();
                }

                if (tokenMarker.Token != null && !(tokenMarker.Token is CommaToken))
                {
                    throw new Exceptions.SyntaxErrorException();
                }

                variableNameTokens.Add((variableNameToken, indicies));
            }

            foreach (var(nameToken, indicies) in variableNameTokens)
            {
                var input = interpreter.Console.ReadChar();
                switch (nameToken.VariableType)
                {
                case VariableValueType.String:
                    string inputString = (input != null) ? input.ToString() : string.Empty;
                    interpreter.VariablesEnvironment.SetVariableValue(nameToken, indicies,
                                                                      interpreter.TokensProvider.CreateStringValueToken(inputString));
                    break;

                case VariableValueType.RealNumber:
                    float realValue;
                    if (input == null)
                    {
                        realValue = 0;
                    }
                    else
                    {
                        if (input >= '0' && input <= '9')
                        {
                            realValue = (float)(input - '0');
                        }
                        else
                        {
                            throw new Exceptions.SyntaxErrorException();
                        }
                    }
                    interpreter.VariablesEnvironment.SetVariableValue(nameToken, indicies,
                                                                      interpreter.TokensProvider.CreateRealValueToken(realValue));

                    break;

                case VariableValueType.IntegerNumber:
                    Int16 intValue;
                    if (input == null)
                    {
                        intValue = 0;
                    }
                    else
                    {
                        if (input >= '0' && input <= '9')
                        {
                            intValue = (Int16)(input - '0');
                        }
                        else
                        {
                            throw new Exceptions.SyntaxErrorException();
                        }
                    }
                    interpreter.VariablesEnvironment.SetVariableValue(nameToken, indicies,
                                                                      interpreter.TokensProvider.CreateIntegerValueToken(intValue));

                    break;
                }

                if (input == null)
                {
                    Thread.Sleep(100);
                }
            }
        }
예제 #30
0
 public override void Execute(Interpreter interpreter, TokenMarker tokenMarker)
 {
     // If used as a primary command, throw a syntax error exception.
     throw new Exceptions.SyntaxErrorException();
 }