Do you have to traverse the syntax tree to determine that?

Yup.