1. The term 'grammar'
As discussed by Aarts (2006: 113), the term grammar can be used in a variety of ways. In a broad sense, grammar can refer to syntax and morphology, as against e.g. phonology or semantics, and may refer more concretely to an explicit description of the morphological and syntactic features of a language. Expanding from this general sense, in more theoretical terms grammar may refer to the system of rules underlying a language-user's linguistic competence, or to an explicitly constructed system of rules which describe or which can generate grammatically correct forms of a language. Expanding again, Universal Grammar refers to the shared underlying linguistic competence common to all humans, on the basis of which individual languages, with their own specific grammars, are formed. In these theoretical senses too, grammar tends to be restricted primarily to syntax and morphology (and often merely syntax), but can also have wider scope.
2. 'Grammar' in the Indian tradition
The closest relevant term in the Indian tradition is vyākaraṇa, which is indeed standardly translated as 'grammar'. Vyākaraṇa as a term refers to an intellectual discipline, a field of science, which includes within its scope much of the range of linguistic analysis which in the West would broadly fall under the term 'grammar'. But its precise scope does not match our term 'grammar' precisely, and the subdivision of linguistic enquiry implied by these terms consequently differs.
Vyākaraṇa as a field developed within a predominantly Brahmanical ritualistic culture. It was in origin one of the six auxiliary disciplines for the study and preservation of the sacred Vedic literature, the vedāṅgas 'limbs of the Veda'. Beside vyākaraṇa, these included three other fields related to the study of language, phonetics (śikṣā), metrics (chandas) and semantic explanations or etymology (nirukta), and the non-language-related disciplines of ritual instruction (kalpa) and astronomy (jyotiṣa).
As evidenced by its earliest surviving work, the Aṣṭādhyāyī of Pāṇini, vyākaraṇa was at an early period the most sophisticated and scientific of the vedāṅgas. Pāṇini's importance in the development of Indian scientific thought has been compared to that of Euclid in the west (e.g. by Staal 1965). The Aṣṭādhyāyī is earliest (surviving) monument of Indian scientific thought, and it was highly influential in the development of the later scientific traditions in India. In this sense the status of the tradition of vyākaraṇa in ancient India was more like that of mathematics or physics in the modern Western world: it was in some sense the original, the prototypical science and a fundamental influence on all other fields of science.
We have no access to the earlier origins of the field of vyākaraṇa; Pāṇini's Aṣṭādhyāyī has in a very fundamental way already moved beyond the origins of vyākaraṇa as a discipline purely for the study and preservation of the Vedas, since the primary focus of the Aṣṭādhyāyī is the spoken language rather than the language of the sacred texts (cf. Emeneau 1955: 145–146). Yet the scope of the Aṣṭādhyāyī, and in consequence the scope of much of the later tradition of vyākaraṇa, remains at least to some extent determined by its position alongside the other vedāṅgas. Phonetics, that is (for the Indian tradition) the study of the articulation of speech sounds, was excluded from the scope of vyākaraṇa, since it fell under the tradition of śikṣā. At least in the Aṣṭādhyāyī, semantic concerns are likewise beyond the purview of vyākaraṇa, since they fell under the tradition of nirukta.
As evidenced by the Aṣṭādhyāyī, at least, vyākaraṇa encompasses the study of the form and formation of linguistic expressions including, in Western terms, the fields of syntax, morphology, and phonology. In this sense it is quite close to the broad sense of English grammar, but including also the study of abstract sound systems. The Indian tradition made no clear division between syntax, morphology and phonology, treating them as a single field of study, and as part of a single system by which the Sanskrit language could be analysed.
Beside the vedāṅgas mentioned above, other later intellectual traditions also engaged in linguistic analysis of the Sanskrit language, including the study of poetics, alaṃkāraśāstra, and the philosophical systems of Mīmāṃsā 'ritual exegesis' and Nyāya 'logic'. But the scope of vyākaraṇa was never restricted by or defined in relation to these traditions, and in fact there was considerable overlap and interaction between these traditions, in particular between vyākaraṇa and the philosophical traditions.
3. 'Generative' grammar
Morphologically, the word vyākaraṇa derives from the verb vi-ā-kṛ, which literally means 'distinguish, separate, differentiate'. In reference to language, it could most naturally be taken therefore to mean 'analysis'. It has alternatively been argued, however, to mean '(word)-formation', based on (some of) the uses of vi-ā-kṛ in reference to language in the Vedic literature.
Whatever the original sense of vyākaraṇa, the earliest surviving output of the tradition, the Aṣṭādhyāyī, is a 'grammar' in the concrete sense of a model of a particular language, Sanskrit. It is not a descriptive or analytical model, but a generative model, which takes as building blocks the base morphological units – verbal roots, nominal stems, particles, affixes, etc. – and produces as output a syntactically coherent phonological representation ready for articulation. As noted by Chomsky (1965: v), the Aṣṭādhyāyī is a 'generative grammar' “in essentially the contemporary sense of this term.”
The Aṣṭādhyāyī was so influential a work that not only was all earlier work of the vyākaraṇa tradition lost, but in addition all later work within the tradition was heavily influenced by it, to the extent that no other type of grammar (e.g. descriptive) of Sanskrit was ever produced within the tradition. This is true even of the so-called 'non-Pāṇinian' grammars. While the 'Pāṇinian' tradition of vyākaraṇa recognized only the authority of the Aṣṭādhyāyī as a grammar of Sanskrit, from the first centuries AD various 'non-Pāṇinian' traditions of vyākaraṇa developed, producing and recognizing as authoritative grammars of Sanskrit other than the Aṣṭādhyāyī. Śarvavarman's Kātantrasūtra (c. 50 AD) and Candragomin's Candrasūtra (c. 450 AD) are two of the most influential among these non-Pāṇinian grammars. But all such grammars remained fundamentally Pāṇinian in the sense of sharing the underlying conception and approach of the Aṣṭādhyāyī, that is taking base morphological units and combining them to form a grammatically correct phonological representation as output.
4. Sanskrit and the underlying aims of vyākaraṇa
While the Aṣṭādhyāyī and other grammars produced within the tradition of vyākaraṇa can be compared with notions of a generative grammar in the modern Western linguistic tradition, the modern notion of a Universal Grammar underlying the grammars of all human languages may have been rather alien to the grammarians of ancient India. In origin, and for the most part, vyākaraṇa had only a single linguistic object: Sanskrit. As the language of the sacred Vedic texts, and as (in slightly different form) the spoken language of the Brahmanical elite who undertook vyākaraṇa, Sanskrit was the divine and perfect language from which one could not meritoriously deviate. Beginning with Tamil in the early centuries AD, traditions of grammatical analysis developed which did take other languages as their object of study. But like the Sanskritic tradition these remained focused on one language, and there was never a search for broader principles underlying the grammars of multiple languages.
Within the Sanskritic tradition of vyākaraṇa there did develop a desire to specify grammatical rules for the Prakrits, forms of Middle Indo-Aryan which became literary languages in close interaction with Sanskrit. In works such as the Siddhahaimacandra of Hemacandra Sūri (12th century AD), rules are given to derive Prakrit forms from Sanskrit bases; that is, one starts with a generative grammar for Sanskrit, and then add rules which take the resulting Sanskrit forms and transform them into Prakrit. This was not so much based on an understanding of the historical relations between Sanskrit and the Prakrits (according to which the latter can be seen to derive from something quite similar to the former), but more based on the idea of Sanskrit as the only perfect, divine, language, such that other languages can only be derivations (or deviations) from it. In this sense, then, one could in fact see the study of Sanskrit, at least for this part of the ancient Indian tradition, as their conception of the study of Universal Grammar.
A related question is the degree to which the tradition of vyākaraṇa was descriptive or prescriptive. For Pāṇini's Aṣṭādhyāyī, at least, the answer appears to be both. “As far as the classical language is concerned, the Aṣṭādhyāyī is simultaneously descriptive and normative: everything it says about Sanskrit is quite clear based on genuine observations of actual usage as well as a native speaker's intuitions about potential usage, but it is at the same time understood that this usage, exactly as described in the grammar, constitutes a norm to be followed by all speakers” (Kiparsky 1979: 4). The Aṣṭādhyāyī notes and licenses grammatical variation, sometimes attributing alternatives to different geographical areas, and as shown by Kiparsky (1979), often marks alternatives as either more common (or, from a prescriptive perspective, preferable) or rarer (/dispreferred).
For the later tradition, Sanskrit was a learned language, no longer anyone's native tongue, and what constituted grammatical Sanskrit was, at least in principle, determined entirely by the prescriptions (as they were seen) of grammatical tradition. That this was not entirely the case is clear from the fact that the later grammarians at times have to force the wording of the Aṣṭādhyāyī to fit the grammar they knew; and in non-Pāṇinian grammars, particularly those of Buddhist and Jain origin, a range of formations not licensed by Pāṇini were accepted and licensed. But even while the normative function of vyākaraṇa was prominent, the purpose of grammar was never purely to distinguish 'correct' linguistic usage from incorrect: understanding the structure of the 'grammatically correct' Sanskrit defined by the Aṣṭādhyāyī (or other grammars), and understanding and refining the grammatical system itself, together with its underlying theoretical assumptions, remained a focus of grammatical inquiry.
5. The later vyākaraṇa tradition
Particularly from the work of Bhartṛhari (c. 500 AD) onwards, the scope of vyākaraṇa as a field widened to include linguistic-philosophical and semantic concerns. In terms of semantics, there developed a concern with understanding and specifying the relations between the linguistic forms produced by the grammar and the verbal knowledge or understanding (śābdabodha) which results from the comprehension of that linguistic form. This includes going beyond the literal meaning of a linguistic expression to include aspects of meaning which are contextually based. In this later stage of the tradition, there is particularly close engagement with the philosophical traditions of Mīmāṃsā and Nyāya, which had similar interest in the nature and functioning of verbal knowledge.
 The task of grammar is to specify word forms, not meanings: the grammar defines which forms are to be used under which semantic conditions, but never what meaning is to be understood from a form (Scharf 2011: 40). As discussed below, semantic concerns become much more prominent in the later vyākaraṇa tradition.
 Phonological concerns are also a part of the tradition of śikṣā, but only as far as concerned the sound correspondences and alternations between the different recitation patterns of the main Vedic texts. The phonological scope of vyākaraṇa encompasses everything relevant to the spoken language, as well as relevant features of the Vedic texts.
 Compare Thieme (1982: 23–34) and Bronkhorst (2011: 10–13).