Beispiel #1
0
        // Reads the statement preceding the index location of the NON-UNARY operator
        // SyntaxException is thrown if the character to the IMMEDIATE left is an operator
        private string ReadLeft(string statement, int operatorIndex)
        {
            if (StatementChecker.IsOperator(statement[operatorIndex - 1]))
            {
                throw new SyntaxException();
            }

            int counter = 1;

            for (int index = operatorIndex - 1; index > -1; index--)
            {
                // Checks for beginning of statement, OR the appearance of the next NON-UNARY operator
                // Returns the number BEFORE the operator

                if (index == 0)
                {
                    return(statement.Substring(index, counter));
                }
                else if (StatementChecker.IsArithmeticOperator(statement[index], statement, index))
                {
                    return(statement.Substring(index + 1, counter - 1));
                }

                counter++;
            }

            return(null);
        }
Beispiel #2
0
        // Reads the statement following index location of the operator
        // Checks for the end of the statement, OR the appearance of the next NON-unary operator
        // Returns the next number AFTER the operator
        private string ReadRight(string statement, int operatorIndex)
        {
            int counter = 1;

            for (int index = operatorIndex + 1; index < statement.Length; index++)
            {
                if (index == statement.Length - 1)
                {
                    return(statement.Substring(operatorIndex + 1, counter));
                }
                else if (StatementChecker.IsArithmeticOperator(statement[index], statement, index))
                {
                    return(statement.Substring(operatorIndex + 1, counter - 1));
                }

                counter++;
            }

            return(null);
        }