public void multAndDivisionCheck(Globals.SUPPORTED_TOKENS previousToken, int index, int numTokens)
        {
            if (previousToken == Globals.SUPPORTED_TOKENS.MINUS ||
                previousToken == Globals.SUPPORTED_TOKENS.PLUS ||
                previousToken == Globals.SUPPORTED_TOKENS.MULTIPLICATION ||
                previousToken == Globals.SUPPORTED_TOKENS.DIVISION ||
                previousToken == Globals.SUPPORTED_TOKENS.INDICIES ||
                previousToken == Globals.SUPPORTED_TOKENS.OPEN_BRACKET)
            {
                if (gatheredTokens[index].GetType() == Globals.SUPPORTED_TOKENS.MULTIPLICATION)
                {
                    throw new InvalidTypeBeforeMultiplicationOperatorException("Integer expected at token position - " + index + ".");
                }
                else if (gatheredTokens[index].GetType() == Globals.SUPPORTED_TOKENS.DIVISION)
                {
                    throw new InvalidTypeBeforeDivisionOperatorException("Integer expected at token position - " + index + ".");
                }
                else if (gatheredTokens[index].GetType() == Globals.SUPPORTED_TOKENS.INDICIES)
                {
                    throw new InvalidTypeBeforeIndiciesOperatorException("Integer expected at token position - " + index + ".");
                }
            }

            if (index + 1 == numTokens)
            {
                throw new MissingExpressionAfterOperatorException("Integer expected at token position - " + (index + 1) + ".");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Method called to process the expression. It assumes that it is in a universal format
 /// as the checking is done by the preprocessor and syntax analyser.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 private double analyseExpressions(double value)
 {
     while (nextToken != null)
     {
         Globals.SUPPORTED_TOKENS tokenType = nextToken.GetType();
         if (tokenType == Globals.SUPPORTED_TOKENS.CONSTANT)
         {
             //If the next token is an int, then just collect the value
             value = Convert.ToDouble(nextToken.GetValue());
             getNextToken();
         }
         else if (tokenType == Globals.SUPPORTED_TOKENS.DIVISION || tokenType == Globals.SUPPORTED_TOKENS.MULTIPLICATION || tokenType == Globals.SUPPORTED_TOKENS.INDICIES)
         {
             //If its division or multiplication, run the appropriate method.
             value = divisionAndMultHandle(value);
         }
         else if (tokenType == Globals.SUPPORTED_TOKENS.PLUS || tokenType == Globals.SUPPORTED_TOKENS.MINUS)
         {
             //same for plus and minus.
             value = plusAndMinusHandle(value);
         }
         else if (tokenType == Globals.SUPPORTED_TOKENS.OPEN_BRACKET)
         {
             //if its an open bracket then recursively call on the expression encapsulated inside
             //the brackets.
             getNextToken();
             value = analyseExpressions(value);
         }
         else if (tokenType == Globals.SUPPORTED_TOKENS.CLOSE_BRACKET)
         {
             //if its a close bracket then just return.
             getNextToken();
             return(value);
         }
         else if (tokenType == Globals.SUPPORTED_TOKENS.VARIABLE_NAME)
         {
             value = variableHandle(value);
         }
     }
     return(value);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Convert the array of characters into a list of tokens.
        /// </summary>
        /// <param name="listOfCharacters"></param>
        /// <param name="listType"></param>
        /// <returns></returns>
        private Token TokeniseList(List <char> listOfCharacters, Globals.SUPPORTED_TOKENS listType)
        {
            var value = "";

            if (listType == Globals.SUPPORTED_TOKENS.PI)
            {
                return(new Token(Globals.SUPPORTED_TOKENS.CONSTANT, Convert.ToString(Math.PI)));
            }

            if (listType == Globals.SUPPORTED_TOKENS.EULER)
            {
                return(new Token(Globals.SUPPORTED_TOKENS.CONSTANT, Convert.ToString(Math.E)));
            }

            foreach (char c in listOfCharacters)
            {
                value += c;
            }

            return(new Token(listType, value));
        }
Exemplo n.º 4
0
 public Operation(Expression left, Globals.SUPPORTED_TOKENS op, Expression right)
 {
     this.left  = left;
     this.op    = op;
     this.right = right;
 }
Exemplo n.º 5
0
 /*
  * Set the token type.
  */
 public void SetType(Globals.SUPPORTED_TOKENS type)
 {
     this.type = type;
 }
Exemplo n.º 6
0
 public Token(Globals.SUPPORTED_TOKENS type, string value)
 {
     this.type  = type;
     this.value = value;
 }
Exemplo n.º 7
0
 public Token()
 {
     type  = Globals.SUPPORTED_TOKENS.WHITE_SPACE;
     value = "";
 }
Exemplo n.º 8
0
        /*
         * Function to tokenise the user's input.
         */
        public List <Token> TokeniseInput(string input)
        {
            if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input))
            {
                throw new EmptyInputException("Error: Empty input added.");
            }

            //Variable to record the token type currently stored in the list of characters.
            Globals.SUPPORTED_TOKENS typeInList = getFirstCharType(input[0]);
            List <char> characters = new List <char>()
            {
                input[0]
            };
            int startPos;

            //Because the unicode is 2 characters in length.
            if (typeInList == Globals.SUPPORTED_TOKENS.EULER)
            {
                startPos = 2;
            }
            else
            {
                startPos = 1;
            }

            //Variable to store the token to be added into the list of tokens.
            Token        tokenToAdd;
            List <Token> tokens = new List <Token>();

            //Go through the line of code added by the user.
            int i;

            for (i = startPos; i < input.Length; i++)
            {
                //Is it a digit?
                if (char.IsDigit(input[i]))
                {
                    //Variable names can contain numbers
                    if (typeInList == Globals.SUPPORTED_TOKENS.VARIABLE_NAME)
                    {
                        characters.Add(input[i]);
                    }
                    //If previous character was a constant then just prepend it onto the list
                    //i.e. characters {2,2} would become 22.
                    else if (typeInList.Equals(Globals.SUPPORTED_TOKENS.CONSTANT))
                    {
                        characters.Add(input[i]);
                    }
                    else
                    {
                        //if it was anything else then create a new token and start again.
                        tokenToAdd = TokeniseList(characters, typeInList);
                        //if the word gathered is a keyword.
                        if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                        {
                            //get the keyword.
                            tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                        }
                        tokens.Add(tokenToAdd);
                        //Create a new list and set the type to CONSTANT
                        characters = new List <char>()
                        {
                            input[i]
                        };
                        typeInList = Globals.SUPPORTED_TOKENS.CONSTANT;
                    }
                }

                else if (input[i] == '+')
                {
                    //+ operator is always 2 seperate tokens not ++.
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.PLUS;
                }

                else if (input[i] == '-')
                {
                    //same for - operator
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.MINUS;
                }
                else if (input[i] == '*' || input[i] == '\u00D7')
                {
                    //same for * operator
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.MULTIPLICATION;
                }
                else if (input[i] == '/' || input[i] == '\u00F7')
                {
                    //same for / operator
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.DIVISION;
                }

                else if (input[i] == '(')
                {
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.OPEN_BRACKET;
                }

                else if (input[i] == '^')
                {
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.INDICIES;
                }

                else if (input[i] == ')')
                {
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.CLOSE_BRACKET;
                }

                else if (input[i] == '=')
                {
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.ASSIGNMENT;
                }

                else if (input[i] == ',')
                {
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.COMMA;
                }
                else if (input[i] == '<')
                {
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.LESS_THAN;
                }
                else if (input[i] == '>')
                {
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.GREATER_THAN;
                }
                //Unicode for PI symbol
                else if (input[i] == '\u03C0')
                {
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.PI;
                }
                //Unicode for Euler's number.
                else if (input[i] == '\uD835')
                {
                    //skip because Euler's unicode has 2 characters
                    i++;
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);
                    characters = new List <char>()
                    {
                        input[i]
                    };
                    typeInList = Globals.SUPPORTED_TOKENS.EULER;
                }
                else if (char.IsLetter(input[i]))
                {
                    //if the previous tokens were variable names
                    if (typeInList.Equals(Globals.SUPPORTED_TOKENS.VARIABLE_NAME))
                    {
                        characters.Add(input[i]);
                    }
                    else
                    {
                        //any other type, create a new token and add it to the list.
                        tokenToAdd = TokeniseList(characters, typeInList);
                        tokens.Add(tokenToAdd);
                        characters = new List <char>()
                        {
                            input[i]
                        };
                        typeInList = Globals.SUPPORTED_TOKENS.VARIABLE_NAME;
                    }
                }
                else if (input[i] == '.')
                {
                    //if it was already a number then just append onto it.
                    if (typeInList.Equals(Globals.SUPPORTED_TOKENS.CONSTANT))
                    {
                        characters.Add(input[i]);
                    }
                    else
                    {
                        //create a new token and add it to the list.
                        tokenToAdd = TokeniseList(characters, typeInList);
                        //if the word gathered is a keyword.
                        if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                        {
                            //get the keyword.
                            tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                        }
                        tokens.Add(tokenToAdd);
                        characters = new List <char>()
                        {
                            input[i]
                        };
                        typeInList = Globals.SUPPORTED_TOKENS.CONSTANT;
                    }
                }
                else if (char.IsWhiteSpace(input[i]))
                {
                    //if whitespace then create a token for it.
                    tokenToAdd = TokeniseList(characters, typeInList);
                    //if the word gathered is a keyword.
                    if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
                    {
                        //get the keyword.
                        tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
                    }
                    tokens.Add(tokenToAdd);

                    //find the next character that is not whitespace
                    while (char.IsWhiteSpace(input[i]))
                    {
                        i++;
                        if (i == input.Length)
                        {
                            break;
                        }
                    }

                    //As long as we haven't hit the end of the string.
                    //We don't want those array index out of bounds tings.
                    if (i != input.Length)
                    {
                        typeInList = getFirstCharType(input[i]);
                        characters = new List <char>()
                        {
                            input[i]
                        };
                    }
                }
                else
                {
                    throw new UnknownCharacterException("Unknown character - " + input[i] + " .");
                }
            }

            //tokenise anything left over.
            tokenToAdd = TokeniseList(characters, typeInList);
            //if the word gathered is a keyword.
            if (Globals.keyWords.Contains(tokenToAdd.GetValue()))
            {
                //get the keyword.
                tokenToAdd.SetType(Globals.getTokenFromKeyword(tokenToAdd.GetValue()));
            }
            tokens.Add(tokenToAdd);

            PrintTokens(tokens);

            return(tokens);
        }
        /// <summary>
        /// Method to launch the syntax analyser to check if it is all okay.
        /// </summary>
        public void checkTokens()
        {
            int bracketLevel = 0;

            if (gatheredTokens[0].GetType() == Globals.SUPPORTED_TOKENS.MULTIPLICATION)
            {
                throw new IncorrectMultiplicationOperatorPositionException("Expression cannot start with a multiplication operator");
            }
            else if (gatheredTokens[0].GetType() == Globals.SUPPORTED_TOKENS.DIVISION)
            {
                throw new IncorrectDivisionOperatorPositionException("Expression cannot start with a division operator");
            }
            else if (gatheredTokens[0].GetType() == Globals.SUPPORTED_TOKENS.CLOSE_BRACKET)
            {
                throw new IncorrectIndiciesOperatorPositionException("Expression cannot start with a close bracket");
            }
            else if (gatheredTokens[0].GetType() == Globals.SUPPORTED_TOKENS.INDICIES)
            {
                throw new IncorrectCloseBracketPositionException("Expression cannot start with a indicies operator");
            }

            Globals.SUPPORTED_TOKENS previousToken = Globals.SUPPORTED_TOKENS.WHITE_SPACE;

            for (int i = 0; i < gatheredTokens.Count; i++)
            {
                switch (gatheredTokens[i].GetType())
                {
                case Globals.SUPPORTED_TOKENS.CONSTANT:
                    //Prevent cases like 2e as you want the user to put 2*e.
                    if (i + 1 != gatheredTokens.Count)
                    {
                        if (gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.VARIABLE_NAME)
                        {
                            throw new VariableAfterConstantException("Cannot have variable name straight after constant. Did you mean " +
                                                                     gatheredTokens[i].GetValue() + "*" + gatheredTokens[(i + 1)].GetValue() + "?");
                        }
                        //for situations like 2pi - you want the user to put 2*pi.
                        if (gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.CONSTANT)
                        {
                            throw new ConstantAfterConstantException("Cannot have a constant straight after constant. Did you mean " +
                                                                     gatheredTokens[i].GetValue() + "*" + gatheredTokens[(i + 1)].GetValue() + "?");
                        }
                    }

                    //Check that only one decimal place has been added or no "." cases
                    int count = gatheredTokens[i].GetValue().Count(x => x == '.');

                    if (count > 1)
                    {
                        throw new InvalidNumberException("Cannot have more than one decimal point in number.");
                    }
                    //if the number specified is just the decimal point.
                    if (gatheredTokens[i].GetValue() == ".")
                    {
                        throw new InvalidNumberException("Unrecognised number - '.'.");
                    }

                    break;

                case Globals.SUPPORTED_TOKENS.OPEN_BRACKET:
                    bracketLevel++;
                    if (i + 1 == gatheredTokens.Count)
                    {
                        throw new IncorrectOpenBracketPositionException("Expression cannot finish with an open bracket.");
                    }

                    //Remove the ability to add ()
                    if (gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.CLOSE_BRACKET)
                    {
                        throw new MissingExpressionBetweenBracketsException("Enclosing brackets must contain an expression.");
                    }

                    break;

                case Globals.SUPPORTED_TOKENS.CLOSE_BRACKET:
                    if (previousToken == Globals.SUPPORTED_TOKENS.MULTIPLICATION ||
                        previousToken == Globals.SUPPORTED_TOKENS.DIVISION ||
                        previousToken == Globals.SUPPORTED_TOKENS.INDICIES)
                    {
                        throw new IncorrectOpenBracketPositionException("Integer expected at token position - " + i + " .");
                    }

                    if (bracketLevel == 0)
                    {
                        throw new MissingOpenBracketException("Close bracket found without supporting open bracket at position - " + i + " .");
                    }
                    bracketLevel--;
                    break;

                case Globals.SUPPORTED_TOKENS.MULTIPLICATION:
                    //prevent situations like 2+*3 because this doesn't make sense.
                    multAndDivisionCheck(previousToken, i, gatheredTokens.Count);
                    break;

                case Globals.SUPPORTED_TOKENS.DIVISION:
                    multAndDivisionCheck(previousToken, i, gatheredTokens.Count);
                    break;

                case Globals.SUPPORTED_TOKENS.ASSIGNMENT:
                    //assignment symbol should be in the 2nd position
                    if (i == 1)
                    {
                        //Only a variable name can be before assignment symbol.
                        if (gatheredTokens[0].GetType() != Globals.SUPPORTED_TOKENS.VARIABLE_NAME)
                        {
                            throw new InvalidTypeBeforeAssignmentOperatorException("Only a variable can be before assignment operator");
                        }

                        //Must have something after the assignment operator
                        if ((i + 1) == gatheredTokens.Count)
                        {
                            throw new MissingExpressionAfterOperatorException("Must have an expression that equates to a value after the assignment operator.");
                        }
                    }
                    else
                    {
                        throw new IncorrectAssignmentOperatorPositionException("Assignment operator found in unexpected token position - " + i + ".");
                    }

                    if (gatheredTokens[(i + 1)].GetType() != Globals.SUPPORTED_TOKENS.PLUS &&
                        gatheredTokens[(i + 1)].GetType() != Globals.SUPPORTED_TOKENS.MINUS &&
                        gatheredTokens[(i + 1)].GetType() != Globals.SUPPORTED_TOKENS.CONSTANT &&
                        gatheredTokens[(i + 1)].GetType() != Globals.SUPPORTED_TOKENS.VARIABLE_NAME &&
                        gatheredTokens[(i + 1)].GetType() != Globals.SUPPORTED_TOKENS.OPEN_BRACKET)
                    {
                        throw new InvalidTypeAfterAssignmentOperatorException("Invalid token " + gatheredTokens[(i + 1)].GetValue() + " found after assignment operator.");
                    }
                    break;

                case Globals.SUPPORTED_TOKENS.MINUS:
                    if ((i + 1) == gatheredTokens.Count)
                    {
                        throw new MissingExpressionAfterOperatorException("Integer expected at token position - " + i + ".");
                    }

                    if (gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.DIVISION ||
                        gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.MULTIPLICATION ||
                        gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.CLOSE_BRACKET ||
                        gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.INDICIES)
                    {
                        throw new InvalidTypeAfterMinusOperatorException("Integer expected at token position - " + i + ".");
                    }
                    break;

                case Globals.SUPPORTED_TOKENS.PLUS:
                    if ((i + 1) == gatheredTokens.Count)
                    {
                        throw new MissingExpressionAfterOperatorException("Integer expected at token position - " + (i + 1) + ".");
                    }

                    if (gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.DIVISION ||
                        gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.MULTIPLICATION ||
                        gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.CLOSE_BRACKET ||
                        gatheredTokens[(i + 1)].GetType() == Globals.SUPPORTED_TOKENS.INDICIES)
                    {
                        throw new InvalidTypeAfterPlusOperatorException("Integer expected at token position - " + (i + 1) + ".");
                    }
                    break;

                case Globals.SUPPORTED_TOKENS.INDICIES:
                    multAndDivisionCheck(previousToken, i, gatheredTokens.Count);
                    break;

                case Globals.SUPPORTED_TOKENS.LESS_THAN:
                    throw new IncorrectLessThanOperatorPositionException("< symbol found in unexpected position.");

                case Globals.SUPPORTED_TOKENS.GREATER_THAN:
                    throw new IncorrectGreaterThanOperatorPositionException("> symbol found in unexpected position.");

                default:
                    break;
                }

                previousToken = gatheredTokens[i].GetType();
            }

            if (bracketLevel != 0)
            {
                throw new MissingCloseBracketException("No supporting closing bracket found.");
            }
        }