In linguistics, syntax describes how words and sentences are put together. Subject-verb agreement, the proper arrangement of direct and indirect objects, and word order are all covered under the subject of syntax. Put simply, syntax refers to grammar, while semantics refers to meaning. Syntax is the set of rules needed to ensure a sentence is grammatically correct; semantics is how one's lexicon, grammatical structure, tone, and other elements of a sentence coalesce to communicate its meaning.
Understanding constituency, the phrase for numerous words working as a single unit, requires knowledge of syntax. Especially when using sentence diagramming, a constituency is required to discern the hierarchy inside large and complicated sentences.
The meaning of a statement frequently changes when a word is rearranged in a sentence. Sometimes the shift is subtle, beneficial for authors who enjoy subtext and subtlety, but other times it is more important, changing the entire meaning of the statement.
For example-
Only Mr. Herald fights crime.
Meaning: Mr. Herald is the only person who fights crime. No one except Mr. Herald fights crime, not even Superman.
Mr. Herald only fights crime.
Meaning: Fighting crime is the only thing Mr. Herald does. He doesn’t work, he doesn’t shower—fighting crime is all he does.
Mr. Herald fights only crime.
Meaning: Mr. Herald doesn’t fight anything except crime. He doesn’t fight Alfred or Ralph; he doesn’t fight waiters if they accidentally stain his shirt. Crime is the only thing he fights.