Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Regular grammar
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Type of formal grammar}} In [[theoretical computer science]] and [[formal language theory]], a '''regular grammar''' is a [[formal grammar|grammar]] that is ''right-regular'' or ''left-regular''. While their exact definition varies from textbook to textbook, they all require that * all [[production (computer science)|production rule]]s have at most one [[Terminal and nonterminal symbols|non-terminal symbol]]; * that symbol is either always at the end or always at the start of the rule's right-hand side. Every regular grammar describes a [[regular language]]. == Strictly regular grammars == A '''right-regular grammar''' (also called [[Linear Grammar#Right-Linear Grammars|right-linear grammar]]) is a formal grammar (''N'', Ξ£, ''P'', ''S'') in which all production rules in ''P'' are of one of the following forms: # ''A'' β ''a'' # ''A'' β ''aB'' # ''A'' β Ξ΅ where ''A'', ''B'', ''S'' β ''N'' are non-terminal symbols, ''a'' β Ξ£ is a terminal symbol, and Ξ΅ denotes the [[empty string]], i.e. the string of length 0. ''S'' is called the start symbol. In a '''left-regular grammar''', (also called [[Linear Grammar#Left-Linear Grammars|left-linear grammar]]), all rules obey the forms # ''A'' β ''a'' # ''A'' β ''Ba'' # ''A'' β Ξ΅ The language described by a given grammar is the set of all strings that contain only terminal symbols and can be derived from the start symbol by repeated application of production rules. Two grammars are called [[weak equivalence (formal languages)|weakly equivalent]] if they describe the same language. Rules of both kinds must not be mixed; for example, the grammar with rule set { ''S''β''aT'', ''T''β''Sb'', SβΞ΅ } is not regular, and describes the language <math>\{ a^i b^i : i \in \mathbb{N} \}</math>, which is not regular, either. Some textbooks and articles disallow empty production rules, and assume that the empty string is not present in languages. == Extended regular grammars == An ''extended right-regular grammar'' is one in which all rules obey one of # ''A'' β ''w'', where ''A'' is a non-terminal in ''N'' and ''w'' is in a (possibly empty) string of terminals Ξ£<sup>*</sup> # ''A'' β ''wB'', where ''A'' and ''B'' are in ''N'' and ''w'' is in Ξ£<sup>*</sup>. Some authors call this type of grammar a ''right-regular grammar'' (or ''right-linear grammar'')<ref>{{cite book | isbn=0-201-02988-X | author=John E. Hopcroft and Jeffrey D. Ullman | title=Introduction to Automata Theory, Languages, and Computation | location=Reading/MA | publisher=Addison-Wesley | year=1979 | url-access=registration | url=https://archive.org/details/introductiontoau00hopc }} Here: p.217 (left, right-regular grammars as subclasses of [[context-free grammar]]s), p.79 (context-free grammars)</ref> and the type above a ''strictly right-regular grammar'' (or ''strictly right-linear grammar'').<ref>Hopcroft and Ullman 1979 (p.229, exercise 9.2) call it a normal form for right-linear grammars.</ref> An ''extended left-regular grammar'' is one in which all rules obey one of # ''A'' β ''w'', where ''A'' is a non-terminal in ''N'' and ''w'' is in Ξ£<sup>*</sup> # ''A'' β ''Bw'', where ''A'' and ''B'' are in ''N'' and ''w'' is in Ξ£<sup>*</sup>. == Examples == An example of a right-regular grammar ''G'' with ''N'' = {S, A}, Ξ£ = {a, b, c}, ''P'' consists of the following rules : S β aS : S β bA : A β Ξ΅ : A β cA and S is the start symbol. This grammar describes the same language as the [[regular expression]] a*bc*, viz. the set of all strings consisting of arbitrarily many "''a''"s, followed by a single "''b''", followed by arbitrarily many "''c''"s. A somewhat longer but more explicit extended right-regular grammar ''G'' for the same regular expression is given by ''N'' = {S, A, B, C}, Ξ£ = {a, b, c}, where ''P'' consists of the following rules: : S β A : A β aA : A β B : B β bC : C β Ξ΅ : C β cC ...where each uppercase letter corresponds to phrases starting at the next position in the regular expression. As an example from the area of programming languages, the set of all strings denoting a floating point number can be described by an extended right-regular grammar ''G'' with ''N'' = {S,A,B,C,D,E,F}, Ξ£ = {0,1,2,3,4,5,6,7,8,9,+,β,.,e}, where S is the start symbol, and ''P'' consists of the following rules: :{| |- || S β +A || A β 0A || B β 0C || C β 0C || D β +E || E β 0F || F β 0F |- || S β βA || A β 1A || B β 1C || C β 1C || D β βE || E β 1F || F β 1F |- || S β A || A β 2A || B β 2C || C β 2C || D β E || E β 2F || F β 2F |- || || A β 3A || B β 3C || C β 3C || || E β 3F || F β 3F |- || || A β 4A || B β 4C || C β 4C || || E β 4F || F β 4F |- || || A β 5A || B β 5C || C β 5C || || E β 5F || F β 5F |- || || A β 6A || B β 6C || C β 6C || || E β 6F || F β 6F |- || || A β 7A || B β 7C || C β 7C || || E β 7F || F β 7F |- || || A β 8A || B β 8C || C β 8C || || E β 8F || F β 8F |- || || A β 9A || B β 9C || C β 9C || || E β 9F || F β 9F |- || || A β .B || || C β eD || || || F β Ξ΅ |- || || A β B || || C β Ξ΅ || || || |} ==Expressive power== There is a direct one-to-one correspondence between the rules of a (strictly) right-regular grammar and those of a [[nondeterministic finite automaton]], such that the grammar generates exactly the language the automaton accepts.<ref>Hopcroft and Ullman 1979, p.218-219, Theorem 9.1 and 9.2</ref> Hence, the right-regular grammars generate exactly all [[regular language]]s. The left-regular grammars describe the reverses of all such languages, that is, exactly the regular languages as well. Every strict right-regular grammar is extended right-regular, while every extended right-regular grammar can be made strict by inserting new non-terminals, such that the result generates the same language; hence, extended right-regular grammars generate the regular languages as well. Analogously, so do the extended left-regular grammars. If empty productions are disallowed, only all regular languages that do not include the empty string can be generated.<ref>Hopcroft and Ullman 1979, p.229, Exercise 9.2</ref> While regular grammars can only describe regular languages, the [[converse (logic)|converse]] is not true: regular languages can also be described by non-regular grammars. ==Mixing left-regular and right-regular rules== If mixing of left-regular and right-regular rules is allowed, we still have a [[linear grammar]], but not necessarily a regular one. What is more, such a grammar need not generate a regular language: all linear grammars can be easily brought into this form, and hence, such grammars can generate exactly all [[linear grammar|linear language]]s, including non-regular ones. For instance, the grammar ''G'' with ''N'' = {S, A}, Ξ£ = {a, b}, ''P'' with start symbol ''S'' and rules : S β aA : A β Sb : S β Ξ΅ generates <math>\{ a^ib^i : i \geq 0\}</math>, the paradigmatic non-regular linear language. ==See also== * [[Regular expression]], a compact notation for regular grammars * [[Regular tree grammar]], a generalization from strings to trees * [[Prefix grammar]] * [[Chomsky hierarchy]] * [[Hidden Markov model]] ==References== {{Reflist}} == Further reading == * {{citation|first1=Dominique|last1=Perrin|contribution=Finite Automata|pages=1β58|editor1-first=Jan van|editor1-last=Leeuwen|title=Formal Models and Semantics|publisher=Elsevier|series=Handbook of Theoretical Computer Science|volume=B|year=1990}} * {{cite book|first1=Jean-Γric|last1=Pin|author-link = Jean-Γric Pin|title=Mathematical Foundations of Automata Theory|url=http://www.liafa.jussieu.fr/~jep/PDF/MPRI/MPRI.pdf|date=Oct 2012}}, chapter III {{Formal languages and grammars}} {{Strings |state=collapsed}} {{DEFAULTSORT:Regular Grammar}} [[Category:Formal languages]]
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Citation
(
edit
)
Template:Cite book
(
edit
)
Template:Formal languages and grammars
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Strings
(
edit
)
Search
Search
Editing
Regular grammar
Add topic