Noun: When "grammar" refers to the system of rules governing the structure and use of a language, it's a noun. For example:
* "I'm studying grammar to improve my writing."
Adjective: When "grammar" describes something related to the rules of language, it's an adjective. For example:
* "She made a grammar error in her sentence."
The specific part of speech depends on its context in the sentence.