本身只是一个数学对象,有四部分组成,是为了正确表达字符串的语法格式,它是任意的线性语法。

线性语法:是文本自由的语法,左线性语法就是在左边最多只有一个非终止标志,右线性语法相反。左右是同等的。

regular grammar is a mathematical object, G, with four components, G = (NΣPS), where

  • is a nonempty, finite set of nonterminal symbols

  • Σ is a finite set of terminal symbols , or alphabet, symbols,

  • P is a set of grammar rules, each of one having one of the forms

    • A → aB

    • A → a

    • A → ε, for A, B ∈ N, a ∈ Σ, and ε the empty string, and

  • S ∈ N is the start symbol. □

Notice that this definition captures all of the components of a regular grammar that we have heretofore identified (heretofor, how often does one get to use that word?

But what does it do?

Pupose:to specify how to form grammatically correct strings in the language of the grammar reprents.

 All strings in Σ* that can be produced from the start symbol by application of the rules of the grammar are in the language of this grammar, all other strings are not. Let's see how we might capture that in a definition.

First we need yet another definition.  We have talked about how strings in a language can be derived by applying the rules of the grammar to nonterminals, starting with the start symbol S.  We now need to make that concept formal.   We do this by defining the operation "derives in one step " as we have used it in our previous examples and exercises by way of the arrow.  For example, we have said that

010110A derives in one step 0101101S

or simply

010110A 0101101S

if there is a rule A → 1S in the grammar we are using.  (Notice that because of the way regular grammars are defined, all intermediate strings on the way to a string in the language have the form "zero or more terminals followed by one nonterminal".)

Definition: Derivations in a Regular Grammar

Let G = (NΣPS) be a regular grammar. We will define three different notations that we use for derivations in G:

      (single step derivations)

 k       (k step derivations)

 *       (derivations of 0 or more steps)

Part 1.  The definition of . We define the operation , called "derives in one step" to be the mapping from strings of the form a1...anA to strings of the form a1... anα, or

a1...anA  a1... anα

if and only if there is a rule

A → α

in P, where each of the a1 are terminal symbols in Σ and A is a nonterminal in N.  (Of course, by the definition of regular grammars, α must have one of the forms bBb, or ε since α is the right hand side of a rule or a regular grammar).

Part 2.  The definition of  k. We further define the operation  k , called a k-step derivation, to be the extension of to k consecutive single-step derivations.  Thus, there is a derivation

a1...anA  k a1...anan+1...an+k-1α

if and only if there are k single-step derivations in G

a1...anA  a1...anan+1A1  ...  a1...anan+1...an+k-1Ak-1  a1...anan+1...an+k-1α

for k ≥ 0.  If k = 0 this just means that no rules are applied, so the string being derived from does not change:

a1...anA  0 a1...anA 

Part 3.  The definition of  * . We define  * to stand for zero or more single step derivations in sequence. □

Finally, we are able to give a formal definition for the set of all strings generated by a grammar G.  We call this set the language of G.

Definition: The Language Generated by a Regular Grammar

Let G = (NΣPS) be a regular grammar.  We define the language generated by G to be L(G)

L(G) = {w | S  * w, where w ∈ Σ*

All this formal definition says is that the language of a regular grammar is the set of all strings over the alphabet Σ that can be derived from the start symbol by application of the grammar rules starting with S.  □

Although this appears to be a lot of words and unnecessary mathematical notation, it turns out to be unbelievably convenient.  From now on we can simply discuss the derivation of strings in a regular grammar by way of the production rules (→) and the three notations for derivations (,  k , and  * ).

http://www.cs.montana.edu/ross/theory/contents/chapter02/green/section05/page04.xhtml