When
Noam Chomsky first formalized generative grammars in 1956, For example, all regular languages can be recognized by a
finite-state machine, and for useful subsets of context-free grammars there are well-known algorithms to generate efficient
LL parsers and
LR parsers to recognize the corresponding languages those grammars generate.
Context-free grammars A
context-free grammar is a grammar in which the left-hand side of each production rule consists of only a single nonterminal symbol. This restriction is non-trivial; not all languages can be generated by context-free grammars. Those that can are called
context-free languages. The language L(G) = \left \{ a^{n}b^{n}c^{n} \mid n \ge 1 \right \} defined above is not a context-free language, and this can be strictly proven using the
pumping lemma for context-free languages, but for example the language \left \{ a^{n}b^{n} \mid n \ge 1 \right \} (at least 1 a followed by the same number of b's) is context-free, as it can be defined by the grammar G_2 with N=\left \{S\right \}, \Sigma=\left \{a,b\right \}, S the start symbol, and the following production rules: : 1. S \rightarrow aSb : 2. S \rightarrow ab A context-free language can be recognized in O(n^3) time (
see Big O notation) by an algorithm such as
Earley's recogniser and in a sub-cubic time by
fast matrix multiplication algorithms. That is, for every context-free language, a machine can be built that takes a string as input and determines in O(n^3) time whether the string is a member of the language, where n is the length of the string.
Deterministic context-free languages is a subset of context-free languages that can be recognized in linear time. There exist various algorithms that target either this set of languages or some subset of it.
Regular grammars In
regular grammars, the left hand side is again only a single nonterminal symbol, but now the right-hand side is also restricted. The right side may be the empty string, or a single terminal symbol, or a single terminal symbol followed by a nonterminal symbol, but nothing else. (Sometimes a broader definition is used: one can allow longer strings of terminals or single nonterminals without anything else, making languages
easier to denote while still defining the same class of languages.) The language \left \{ a^{n}b^{n} \mid n \ge 1 \right \} defined above is not regular, but the language \left \{ a^{n}b^{m} \mid m,n \ge 1 \right \} (at least 1 a followed by at least 1 b, where the numbers may be different) is, as it can be defined by the grammar G_3 with N=\left \{S, A,B\right \}, \Sigma=\left \{a,b\right \}, S the start symbol, and the following production rules: :# S \rightarrow aA :# A \rightarrow aA :# A \rightarrow bB :# B \rightarrow bB :# B \rightarrow \epsilon All languages generated by a regular grammar can be recognized in O(n) time by a finite-state machine. Although in practice, regular grammars are commonly expressed using
regular expressions, some forms of regular expression used in practice do not strictly generate the regular languages and do not show linear recognitional performance due to those deviations.
Other forms of generative grammars Many extensions and variations on Chomsky's original hierarchy of formal grammars have been developed, both by linguists and by computer scientists, usually either in order to increase their expressive power or in order to make them easier to analyze or parse. Some forms of grammars developed include: •
Tree-adjoining grammars increase the expressiveness of conventional generative grammars by allowing rewrite rules to operate on
parse trees instead of just strings. •
Affix grammars and
attribute grammars allow rewrite rules to be augmented with semantic attributes and operations, useful both for increasing grammar expressiveness and for constructing practical language translation tools.
Recursive grammars A recursive grammar is a grammar that contains production rules that are
recursive. For example, a grammar for a
context-free language is
left-recursive if there exists a non-terminal symbol
A that can be put through the production rules to produce a string with
A as the leftmost symbol. An example of recursive grammar is a clause within a sentence separated by two commas. All types of grammars in the
Chomsky hierarchy can be recursive. == Analytic grammars ==