In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
, a linear grammar is a
context-free grammar
In formal language theory, a context-free grammar (CFG) is a formal grammar whose production rules are of the form
:A\ \to\ \alpha
with A a ''single'' nonterminal symbol, and \alpha a string of terminals and/or nonterminals (\alpha can be ...
that has at most one nonterminal in the
right-hand side
In mathematics, LHS is informal shorthand for the left-hand side of an equation. Similarly, RHS is the right-hand side. The two sides have the same value, expressed differently, since equality is symmetric.regular language
In theoretical computer science and formal language theory, a regular language (also called a rational language) is a formal language that can be defined by a regular expression, in the strict sense in theoretical computer science (as opposed to ...
s.
A
regular grammar
In theoretical computer science and formal language theory, a regular grammar is a grammar that is ''right-regular'' or ''left-regular''.
While their exact definition varies from textbook to textbook, they all require that
* all production rules ...
is a grammar that is left-linear or right-linear.
Observe that by inserting new nonterminals, any linear grammar can be replaced by an equivalent one where some of the rules are left-linear and some are right-linear. For instance, the rules of ''G'' above can be replaced with
: S → aA
: A → Sb
: S → ε
However, the requirement that ''all'' rules be left-linear (or all rules be right-linear) leads to a strict decrease in the expressive power of linear grammars.
Expressive power
All regular languages are linear; conversely, an example of a linear, non-regular language is . as explained above.
All linear languages are
context-free; conversely, an 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
In mathematics, set ''A'' is a subset of a set ''B'' if all elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they are unequal, then ''A'' is a proper subset o ...
of the linear languages, which in turn are a proper subset of the context-free languages.
While regular languages are
deterministic
Determinism is a philosophical view, where all events are determined completely by previously existing causes. Deterministic theories throughout the history of philosophy have developed from diverse and sometimes overlapping motives and consi ...
, there exist linear languages that are nondeterministic. For example, the language of even-length
palindrome
A palindrome is a word, number, phrase, or other sequence of symbols that reads the same backwards as forwards, such as the words ''madam'' or ''racecar'', the date and time ''11/11/11 11:11,'' and the sentence: "A man, a plan, a canal – Panam ...
s on the alphabet of 0 and 1 has the linear grammar S → 0S0 , 1S1 , ε. An arbitrary string of this language cannot be parsed without reading all its letters first which means that a pushdown automaton has to try alternative state transitions to accommodate for the different possible lengths of a semi-parsed string. This language is nondeterministic. Since nondeterministic context-free languages cannot be accepted in linear time, linear languages cannot be accepted in linear time in the general case. Furthermore, it is undecidable whether a given context-free language is a linear context-free language.
Closure properties
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
In algebra, a homomorphism is a structure-preserving map between two algebraic structures of the same type (such as two groups, two rings, or two vector spaces). The word ''homomorphism'' comes from the Ancient Greek language: () meaning "sa ...
and
inverse homomorphism.
[John E. Hopcroft and Jeffrey D. Ullman, '']Introduction to Automata Theory, Languages, and Computation
''Introduction to Automata Theory, Languages, and Computation'' is an influential computer science textbook by John Hopcroft and Jeffrey Ullman on formal languages and the theory of computation. Rajeev Motwani contributed to later edition ...
'', Addison-Wesley Publishing, Reading Massachusetts, 1979. ., Ex. 11.1, pp. 282f 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.
References
{{DEFAULTSORT:Linear Grammar
Formal languages