11
Context-Free Grammars – Regular Grammars Lecture 14 Section 2.1 Fri, Sep 21, 2007

Context-Free Grammars – Regular Grammars

  • Upload
    darena

  • View
    87

  • Download
    0

Embed Size (px)

DESCRIPTION

Context-Free Grammars – Regular Grammars. Lecture 14 Section 2.1 Fri, Sep 21, 2007. Regular Grammars. Yet another way to describe regular languages is through regular grammars . Start symbol S . Set of variables V . Set of terminal symbols  . Set of rules R. Regular Grammars. - PowerPoint PPT Presentation

Citation preview

Page 1: Context-Free Grammars – Regular Grammars

Context-Free Grammars – Regular Grammars

Lecture 14Section 2.1

Fri, Sep 21, 2007

Page 2: Context-Free Grammars – Regular Grammars

Regular Grammars

• Yet another way to describe regular languages is through regular grammars. • Start symbol S.• Set of variables V.• Set of terminal symbols .• Set of rules R.

Page 3: Context-Free Grammars – Regular Grammars

Regular Grammars

• Each rule is of one of the following forms:• A aB• A

where A and B are variables and a is a terminal.

Page 4: Context-Free Grammars – Regular Grammars

Regular Grammars

• Then we begin with the start symbol and apply rules until we obtain a string of all terminals.

Page 5: Context-Free Grammars – Regular Grammars

Example

• Let the rules be• S aX• S bY• S • X aS• X bZ• X • :

Page 6: Context-Free Grammars – Regular Grammars

Example

• Y aY• Y bY• Y • Z aY• Z bX

Page 7: Context-Free Grammars – Regular Grammars

Example

• What strings can be obtained by these rules?

• One example:• S aX aaS aabY aab.

• Another example:• S bY bbY bbaY bba.

Page 8: Context-Free Grammars – Regular Grammars

The Language of a Grammar

• The set of all strings obtainable from the grammar, by starting with the start symbol, is called the language of the grammar.

Page 9: Context-Free Grammars – Regular Grammars

Regular Grammars and Regular Languages

• It is easy to derive a regular grammar from a DFA, and vice versa.

Page 10: Context-Free Grammars – Regular Grammars

Regular Grammars and Regular Languages

• Given a DFA, • Let V be the set of states Q.• The start symbol is the start state.• For each transition (p, a) = q, write a

rule p aq.• For each accept state q, write a rule q

.

• This process is reversible.

Page 11: Context-Free Grammars – Regular Grammars

Example

• Construct a DFA from the previous example.

• What is the language of the grammar?