In linguistics, grammar is the set of structural rules that govern the composition of sentences, phrases, and words in any given natural language. The term refers also to the study of such rules, and this field includes morphology, syntax, and phonology, often complemented by phonetics, semantics, and pragmatics. Linguists do not normally use the term to refer to orthographical rules, although usage books and style guides that call themselves grammars may also refer to spelling and punctuation.
Grammar is a conspiracy theory about a supposed set of unstable rules that try to govern the composition of words, words, and did I mention even more words in only English (because the rest are phonies).
The term grammar also refers also to the study of pudding, fat, and calories. Linguists always use the words pudding, fat, and calories to refer to grammar, words, and something called punctuation.