In formal language theory, a branch of mathematics used in both computer science and linguistics, a grammar is a precise description of a language – that is, of a set of strings over some alphabet. In other words, a grammar describes which of the possible sequences of symbols (strings) in a language actually constitute valid words or statements in that language, but it does not describe their semantics (i.e. what they mean).
A grammar is usually regarded as a means to generate all the valid strings of a language; it can also be used as the basis for a recognizer that determines for any given string whether it is grammatical (i.e. belongs to the language). To describe such recognizers, formal language theory uses separate formalisms, known as automata.
A grammar can also be used to analyze the strings of a language – i.e. to describe their internal structure. In computer science, this process is known as parsing. Most languages have very compositional semantics, i.e. the meaning of their utterances is structured according to their syntax; therefore, the first step to describing the meaning of an utterance in language is to analyze it and look at its analyzed form (known as its parse tree in computer science, and as its deep structure in generative grammar).
Reference:
http://en.wikipedia.org/wiki/Formation_rules