check prev_data.syntax_stack attribute before reading it

rather than just checking whether prev_data is non-None.

closes #3128