The spectra of nonnegative matrices via symbolic dynamics