Sei sulla pagina 1di 2

Regular grammar a regular grammar is a formal grammar that describes a regular language.

Strictly regular grammars


A right regular grammar (also called right linear grammar) is a formal grammar (N, , P, S) such that all the production rules in P are of one of the following forms: 1. B a - where B is a non-terminal in N and a is a terminal in 2. B aC - where B and C are in N and a is in 3. B - where B is in N and denotes the empty string, i.e. the string of length 0. In a left regular grammar (also called left linear grammar), all rules obey the forms 1. A a - where A is a non-terminal in N and a is a terminal in 2. A Ba - where A and B are in N and a is in 3. A - where A is in N and is the empty string. 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*. A regular grammar is a left or right regular grammar. Some textbooks and articles disallow empty production rules, and assume that the empty string is not present in languages.

[edit] Extended regular grammars


An extended right regular grammar is one in which all rules obey one of 1. B a - where B is a non-terminal in N and a is a terminal in 2. A wB - where A and B are in N and w is in * 3. A - where A is in N and is the empty string. Some authors call this type of grammar a right regular grammar (or right linear grammar) and the type above a strictly right regular grammar (or strictly right linear grammar). An extended left regular grammar is one in which all rules obey one of

1. A a - where A is a non-terminal in N and a is a terminal in 2. A Bw - where A and B are in N and w is in * 3. A - where A is in N and is the empty string. Some authors call this type of grammar a left regular grammar and the type above a strictly left regular grammar.

[edit] Expressive power


There is a direct one-to-one correspondence between the rules of a (strictly) left regular grammar and those of a nondeterministic finite state automaton, such that the grammar generates exactly the language the automaton accepts. Hence, the left regular grammars generate exactly all regular languages. The right 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 nonterminals, 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.

Properties of regular languages


Let L1 and L2 be two regular languages. 1. L1 u L2 is regular. 2. L1 .L2 is regular. 3. L1* is regular. 4. L1Ris regular. 5. L1 =sigma-L1 is regular. 6. L1 intersection L2 is regular.

Potrebbero piacerti anche