Refactor checkCharacterPrecedence and create stack