In computer science, a grammar is linear if it is context-free and all of its productions' right hand sides have at most one nonterminal.
A linear language is a language generated by some linear grammar.
Contents |
A simple linear grammar is G with N = {S}, Σ = {a, b}, P with start symbol S and rules
It generates the language .
Two special types of linear grammars are the following:
Collectively, these two special types of linear grammars are known as the regular grammars; both can describe exactly the regular languages.
Another special type of linear grammar is the following:
By inserting new nonterminals, every linear grammar can be brought into this form without affecting the language generated. For instance, the rules of G above can be replaced with
Hence, linear grammars of this special form can generate all linear languages.
We have seen that all regular languages are linear; the example gave a linear, non-regular language. All linear languages are context-free by definition; a simple example of a context-free, non-linear language is the Dyck language of well-balanced bracket pairs.
Hence, the regular languages are a proper subset of the linear ones, which in turn are a proper subset of the context-free languages.
If L is a linear language and M is a regular language, then the intersection is again a linear language; in other words, the linear languages are closed under intersection with regular sets. Furthermore, the linear languages are closed under homomorphism and inverse homomorphism[1]. These three closure properties show that the linear languages form a full trio. Full trios in general are language families that enjoy a couple of other desirable mathematical properties.