private Stack<Symbol> parseNextAlgebraicSymbol(String inputExpression, int index, Stack<Symbol> parseTree) {
        char symbol = inputExpression.charAt(index);
        if (Character.isLetterOrDigit(symbol)) {
            parseTree = insertNumberOrVariable(inputExpression, index, parseTree, Character.isLetter(symbol));
        }
        else if (symbol == '+') {
            Add operator = new Add();
            operator.addPrecedence(accumulatedPrecedence);
            lastValidInput = null;
            parseTree = insertSymbolByPrecedence(operator, parseTree);
        }
        else if (symbol == '-') {
            Symbol operator = lastValidInput == null ? new Negate() : new Subtract();
            operator.addPrecedence(accumulatedPrecedence);
            lastValidInput = null;
            parseTree = insertSymbolByPrecedence(operator, parseTree);
        }
        else if (symbol == '*') {
            Multiply operator = new Multiply();
            operator.addPrecedence(accumulatedPrecedence);
            lastValidInput = null;
            parseTree = insertSymbolByPrecedence(operator, parseTree);
        }
        else if (symbol == '/') {
            Divide operator = new Divide();
            operator.addPrecedence(accumulatedPrecedence);
            lastValidInput = null;
            parseTree = insertSymbolByPrecedence(operator, parseTree);
        }
        else if (symbol == '(') {
            parseTree = handleParentheses(inputExpression, index, parseTree, "algebraic");
        }
        else if (inputExpression.charAt(index) == ' ' || inputExpression.charAt(index) == '\n') {
            // Skip whitespace
        }

        return parseTree;
    }