Grammars

Grammar Concepts

Definition
A grammar G is a quadruple grammars1.jpg where

Productions have form grammars3.jpg where

Application of productions, given grammars6.jpg :

grammars11.jpg
means that grammars12.jpg derives grammars13.jpg in zero or more production steps.
Definition
Let grammars14.jpg be a grammar. Then grammars15.jpg is the language generated by G.

That is, L(G) is the set of all strings that can be generated from the start symbol S using the productions P.

A derivation of some sentence grammars16.jpg is a sequence

grammars17.jpg

The strings grammars18.jpg above are sentential forms of the derivation of sentence w.

Grammar Example

Consider grammars19.jpg where P is

Consider grammars22.jpg , hence, grammars23.jpg .

aabb is a sentence of the language; the other strings in the derivation are sentential forms.

Conjecture:
The language formed by this grammar, L(G), is grammars24.jpg

Usually, however, it is difficult to construct an explicit set definition of a language generated by a grammar.

Now prove the conjecture.

First prove that all sentential forms of the language have the structure grammars25.jpg for grammars26.jpg by induction on i.

Basis step:
Clearly, grammars27.jpg is a sentential form, the start symbol.

Inductive step:
Assume grammars28.jpg is a sentential form, show that grammars29.jpg .

Case 1: If we begin with the assumption and apply production grammars30.jpg , we get sentential form grammars31.jpg .

Case 2: If we begin with the assumption and apply production grammars32.jpg , we get the sentence grammars33.jpg rather than a sentential form.

Hence, all sentential forms have the form grammars34.jpg .

Given that grammars35.jpg is the only production with terminals on the right side, we must apply it to derive any sentence. As we noted in case 2 above, application of the production to any sentential form gives a sentence of the form grammars36.jpg .

Example: Finding a Grammar for a Language

Given grammars37.jpg .

A slightly different grammar might introduce nonterminal A as follows:

More Grammar Concepts

To show that a language L is generated by a grammar G, we must prove:

  1. For every grammars44.jpg , there is a derivation using G.
  2. Every string derived from G is in L.

Two grammars are equivalent if they generate the same language.

For example, the two grammars given above for the language grammars45.jpg are equivalent.


[Next]


Copyright © 1999, H. Conrad Cunningham
Last modified: Mon Aug 23 08:39:05 CDT 1999