Some dictionary definitions
gram·mar (grmr)n.
1. a. The study of how words and their component parts combine to form sentences.
b. The study of structural relationships in language or in a language, sometimes including pronunciation, meaning, and linguistic history.
2. a. The system of inflections, syntax, and word formation of a language.
b. The system of rules implicit in a language, viewed as a mechanism for generating all sentences possible in that language.
3. a. A normative or prescriptive set of rules setting forth the current standard of usage for pedagogical or reference purposes.
b. Writing or speech judged with regard to such a set of rules.
4. A book containing the morphologic, syntactic, and semantic rules for a specific language.
5. a. The basic principles of an area of knowledge: the grammar of music.
b. A book dealing with such principles.
A working definition of what grammar is for the language learner:
The knowledge and skills needed to combine (letters and) words to make meaning, usually in sentences. (Rachel Hawkes)
What others have to say about grammar:
“What I know about grammar is its infinite power. To shift the structure of a sentence alters the meaning of that sentence.”
American essayist and novelist Joan Didion, quoted by Donald Murray in Writing to Deadline: The Journalist at Work (Heinemann, 2000).
“Grammar is the structural foundation of our ability to express ourselves. The more we are aware of how it works, the more we can monitor the meaning and effectiveness of the way we and others use language. It can help foster precision, detect ambiguity, and exploit the richness of expression available in English. And it can help everyone—not only teachers of English, but teachers of anything, for all teaching is ultimately a matter of getting to grips with meaning.”
"In Word and Deed." David Crystal, TES Teacher, April 30, 2004